Pagini recente » Cod sursa (job #2926661) | Cod sursa (job #2148516) | Cod sursa (job #382482) | Cod sursa (job #2438993) | Cod sursa (job #3258633)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int main()
{
int n;
fin >> n;
int tot[n];
for (int i=1; i<=n; i++) {
tot[i] = i;
}
for (int i=2; i<=n; i++) {
if (tot[i] == i) {
tot[i] -= 1; // phi(i) = i-1 daca i prim
for (int j=2; i*j <= n; j++) {
tot[i*j] = tot[i*j]/i * (i-1);
}
}
}
/*
for (int i = 1; i<=n; i++) {
cout << tot[i] << " ";
}
*/
long long sol = 0;
for (int i=2; i<=n; i++) {
sol += tot[i];
}
sol = 2*sol + 1;
cout << sol;
return 0;
}