0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

P2158 [SDOI2008] 仪仗队

R59168867
This commit is contained in:
Baoshuo Ren 2021-10-05 10:18:21 +08:00 committed by Baoshuo Ren
parent 3a7df52d71
commit bf69b6fcb3
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -2,22 +2,30 @@
using namespace std;
int n, ans, f[50000];
int n, p, ans, mu[40005], primes[40005];
bool vis[40005];
int main() {
cin >> n;
ans = (n - 1) * (n - 1);
if(!--n) {
if (!--n) {
cout << 0 << endl;
return 0;
exit(0);
}
for (int i = n; i >= 2; i--) {
f[i] = (n / i) * (n / i);
for (int j = 2 * i; j <= n; j += i) {
f[i] -= f[j];
mu[1] = 1;
for (int i = 2; i <= n; i++) {
if (!vis[i]) {
primes[++p] = i;
mu[i] = -1;
}
ans -= f[i];
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);
}
cout << ans + 2 << endl;
return 0;
}
}