Cod sursa(job #2271064)
| Utilizator | Data | 27 octombrie 2018 23:16:13 | |
|---|---|---|---|
| Problema | Fractii | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.49 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("fractii.in");
ofstream out("fractii.out");
int n;
ll ans, cnt[1000100], phi[1000100];
int main() {
in >> n;
for (int i = 1; i <= n; i++)
phi[i] = i;
for (int i = 2; i <= n; i++) {
if (cnt[i])
continue;
phi[i]--;
cnt[i]++;
for (int j = i + i; j <= n; j += i) {
phi[j] -= j / i;
cnt[j]++;
}
}
for (int i = 1; i <= n; i++)
ans += phi[i] + cnt[i] - 1;
ans++;
out << 2LL * ans - 1LL;
return 0;
}