Cod sursa(job #3202230)
Utilizator | Verde Flaviu-Cristian verde.cristian2005 | Data | 11 februarie 2024 10:26:27 |
---|---|---|---|
Problema | Fractii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("fractii.in");
ofstream out("fractii.out");
int phi[1000001];
int main()
{
int n;
in >> n;
for(int i = 2; i <= n; i++)
phi[i] = i;
long long rez = 1;
for(int i = 2; i <= n; i++)
{
if(phi[i] == i)
for(int j = i; j <= n; j += i)
phi[j] = phi[j] / i * (i - 1);
rez += 2 * phi[i];
}
out << rez;
return 0;
}