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

T243086 最简分数列

https://www.luogu.com.cn/record/76645289
This commit is contained in:
Baoshuo Ren 2022-05-29 18:44:10 +08:00
parent 2d7ebcf9e4
commit 61b9f35904
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

43
Luogu/T243086/T243086.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
int n, p, primes[10000005], phi[10000005];
bool vis[10000005];
long long ans;
void get_eulers(int n) {
phi[1] = 1;
for (int i = 2; i <= n; i++) {
if (!vis[i]) {
primes[p++] = i;
phi[i] = i - 1;
}
for (int j = 0; primes[j] * i <= n; j++) {
vis[primes[j] * i] = true;
if (i % primes[j] == 0) {
phi[primes[j] * i] = phi[i] * primes[j];
break;
}
phi[primes[j] * i] = phi[i] * (primes[j] - 1);
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
get_eulers(n);
for (int i = 2; i <= n; i++) {
ans += phi[i];
}
cout << ans << endl;
return 0;
}