Pagini recente » Cod sursa (job #881689) | Cod sursa (job #2535357) | Cod sursa (job #3258783) | Cod sursa (job #1562106) | Cod sursa (job #3258634)
#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;
fout << sol;
return 0;
}