Pagini recente » Cod sursa (job #943835) | Cod sursa (job #3191900) | Cod sursa (job #135553) | Cod sursa (job #2273191) | Cod sursa (job #2244714)
#include <fstream>
using namespace std;
ifstream in("sum.in");
ofstream out("sum.out");
const int N_MAX = 100000;
int totient[N_MAX + 1], X[N_MAX + 1];
void compute_totient2(int N) {
for(int i = 1; i <= N; i++)
totient[i] = i;
for(int i = 2; i <= N; i++)
if(totient[i] == i)
for(int j = i; j <= N; j += i)
totient[j] -= totient[j] / i;
}
int main()
{
int N, X_max = 0;
in >> N;
for(int i = 1; i <= N; i++) {
in >> X[i];
X_max = max(X_max, X[i]);
}
compute_totient2(X_max);
for(int i = 1; i <= N; i++)
out << 1LL * 2 * totient[X[i]] * X[i] << '\n';
return 0;
}