0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 00:45:26 +00:00
OI-codes/Luogu/P2158/P2158.cpp

32 lines
649 B
C++
Raw Normal View History

2021-02-02 07:38:43 +00:00
#include <bits/stdc++.h>
using namespace std;
2021-10-05 02:18:21 +00:00
int n, p, ans, mu[40005], primes[40005];
bool vis[40005];
2021-02-02 07:38:43 +00:00
int main() {
cin >> n;
2021-10-05 02:18:21 +00:00
if (!--n) {
2021-02-02 07:38:43 +00:00
cout << 0 << endl;
2021-10-05 02:18:21 +00:00
exit(0);
2021-02-02 07:38:43 +00:00
}
2021-10-05 02:18:21 +00:00
mu[1] = 1;
for (int i = 2; i <= n; i++) {
if (!vis[i]) {
primes[++p] = i;
mu[i] = -1;
2021-02-02 07:38:43 +00:00
}
2021-10-05 02:18:21 +00:00
for (int j = 1; i * primes[j] <= n; j++) {
vis[i * primes[j]] = true;
if (i % primes[j] == 0) break;
mu[i * primes[j]] = -mu[i];
}
}
for (int i = 1; i <= n; i++) {
ans += mu[i] * pow(n / i, 2);
2021-02-02 07:38:43 +00:00
}
cout << ans + 2 << endl;
return 0;
2021-10-05 02:18:21 +00:00
}