Pagini recente » Istoria paginii utilizator/ioanamuresan | Monitorul de evaluare | Monitorul de evaluare | Istoria paginii utilizator/dragan_daniela_liliana_322cc | Cod sursa (job #1253485)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <string>
using namespace std;
int phi[100007];
void sigma(int n) {
for(int i = 0; i <= n; i++) {
phi[i] = i;
}
for(int i = 2; i <= n; i++) {
if(phi[i] == i) {
for(int j = i; j <= n; j += i) {
phi[j] /= i;
phi[j] *= (i - 1);
}
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("sum.in", "r", stdin);
freopen("sum.out", "w", stdout);
#endif
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
string s;
getline(cin, s, '\0');
istringstream iss(s);
ostringstream oss;
int n, x;
iss >> n;
sigma(100007);
for(int i = 0; i < n; i++)
{
iss >> x;
oss << 2LL * phi[x] * x << "\n";
}
cout << oss.str();
return 0;
}