【题目链接】
【思路要点】
- 补档博客,无题解。
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 5005 template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } long long phi(long long x) { long long ans = x, i = 2; while (i * i <= x) { if (x % i == 0) ans = ans / i * (i - 1); while (x % i == 0) x /= i; i++; } if (x != 1) ans = ans / x * (x - 1); return ans; } int main() { long long n, ans = 0; read(n); for (long long i = 1; i * i <= n; i++) { if (n % i) continue; if (i * i == n) ans += i * phi(i); else ans += i * phi(n / i) + n / i * phi(i); } cout << ans << endl; return 0; }