0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 19:36:28 +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,21 +2,29 @@
using namespace std; using namespace std;
int n, ans, f[50000]; int n, p, ans, mu[40005], primes[40005];
bool vis[40005];
int main() { int main() {
cin >> n; cin >> n;
ans = (n - 1) * (n - 1); if (!--n) {
if(!--n) {
cout << 0 << endl; cout << 0 << endl;
return 0; exit(0);
} }
for (int i = n; i >= 2; i--) { mu[1] = 1;
f[i] = (n / i) * (n / i); for (int i = 2; i <= n; i++) {
for (int j = 2 * i; j <= n; j += i) { if (!vis[i]) {
f[i] -= f[j]; 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; cout << ans + 2 << endl;
return 0; return 0;