Cod sursa(job #2122892)
| Utilizator | Data | 5 februarie 2018 16:59:46 | |
|---|---|---|---|
| Problema | Fractii | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000007;
long long phi[maxn];
void sieve() {
for (int i = 1; i <= maxn; i++) {
phi[i] = i - 1;
}
for (int i = 2; i <= maxn; i++) {
for (int j = 2*i; j <= maxn; j += i) {
phi[j] -= phi[i];
}
}
}
int main() {
freopen("fractii.in", "r", stdin);
freopen("fractii.out", "w", stdout);
int n;
cin >> n;
sieve();
long long sol = 0;
for (int i = 1; i <= n; i++) {
sol += phi[i] * 2;
}
cout << sol + 1 << "\n";
return 0;
}