Pagini recente » Cod sursa (job #275919) | Cod sursa (job #973195) | Cod sursa (job #2457535) | Cod sursa (job #1863050) | Cod sursa (job #3258694)
#include <iostream>
#include <fstream>
using namespace std;
#define LL long long
ifstream fin("sum.in");
ofstream fout("sum.out");
int phi(int n) {
int tot[n+1];
for (int i=1; i<=n; i++) {
tot[i] = i;
}
for (int i=2; i<=n; i++) {
if (tot[i] == i) {
tot[i]--; // phi(i) = i-1 daca i prim
for (int j=2; i*j <= n; j++) {
tot[i*j] = tot[i*j]/i * (i-1);
}
}
}
return tot[n];
}
int main()
{
int n; fin >> n;
for (int i=0; i<n; i++) {
int x; fin >> x;
LL s = (LL)phi(x) * (LL)x * (LL)2;
fout << s << endl;
cout << s << endl;
}
return 0;
}