0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:25:24 +00:00

P2398 GCD SUM

https://www.luogu.com.cn/record/80288917
This commit is contained in:
Baoshuo Ren 2022-07-19 19:40:13 +08:00
parent 1093bfa649
commit b634d12e32
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

42
Luogu/P2398/P2398.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
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;
}