Cod sursa(job #1253488)

Utilizator space.foldingAdrian Soucup space.folding Data 1 noiembrie 2014 13:32:04
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#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
	
	int n, x;

	scanf("%d", &n);
	sigma(100007);

	for(int i = 0; i < n; i++)
	{
		scanf("%d", &x);
		printf("%lld\n", 2LL * phi[x] * x);
	}	
	return 0;
}