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