Cod sursa(job #3217693)
Utilizator | Hanganu Darius DariusH | Data | 24 martie 2024 13:15:16 |
---|---|---|---|
Problema | Fractii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
#define N_MAX 1000001
int phi[N_MAX];
int main()
{
int n, i, j;
long long res;
fin >> n;
for(i = 1; i <= n; ++i) {
phi[i] = i;
}
for(i = 2; i <= n; ++i) {
if(phi[i] == i) {
for(j = i; j <= n; j += i) {
phi[j] = phi[j] / i * (i - 1);
}
}
}
res = 0;
for(i = 1; i <= n; ++i) {
res += phi[i];
}
fout << res * 2 - 1 << '\n';
return 0;
}