Pagini recente » Cod sursa (job #1212788) | Cod sursa (job #1198783) | Cod sursa (job #347421) | Cod sursa (job #2696242) | Cod sursa (job #3258704)
#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];
}
*/
const int n = 100000;
int tot[n+1];
int main()
{
int a; fin >> a;
// calculez dinainte tot pana la nr maxim din problema (100 000)
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);
}
}
}
// rezolvare
for (int i=0; i<a; i++) {
LL x; fin >> x;
LL s = (LL)tot[x] * x * (LL)2;
fout << s << endl;
}
return 0;
}