Cod sursa(job #1253476)

Utilizator space.foldingAdrian Soucup space.folding Data 1 noiembrie 2014 13:23:59
Problema Sum Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <cstdio>
#include <cmath>
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

	int n, x;

	cin >> n;

	sigma(100007);

	for(int i = 0; i < n; i++)
	{
		cin >> x;
		cout << phi[x] * x * 2 << endl;
	}

	return 0;
}