diff --git a/Luogu/P2398/P2398.cpp b/Luogu/P2398/P2398.cpp new file mode 100644 index 00000000..a7b9c93d --- /dev/null +++ b/Luogu/P2398/P2398.cpp @@ -0,0 +1,42 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, phi[N]; +long long sum[N], ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + phi[1] = 1; + for (int i = 2; i <= n; i++) { + phi[i] = i; + } + + for (int i = 2; i <= n; i++) { + if (phi[i] == i) { + for (int j = i; j < N; j += i) { + phi[j] = phi[j] / i * (i - 1); + } + } + } + + for (int i = 1; i <= n; i++) { + sum[i] = sum[i - 1] + phi[i]; + } + + for (int i = 1; i <= n; i++) { + ans += (sum[n / i] * 2 - 1) * i; + } + + cout << ans << endl; + + return 0; +}