Cod sursa(job #775390)

Utilizator visanrVisan Radu visanr Data 7 august 2012 23:44:29
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define nmax 100000

int phi[100010], T, X;

int main()
{
    freopen("sum.in", "r", stdin);
    freopen("sum.out", "w", stdout);
    int i, j;
    for(i = 1; i <= nmax; i++) phi[i] = i;
    for(i = 2; i <= nmax; i++)
          if(phi[i] == i)
                    for(j = i; j <= nmax; j += i) phi[j] /= i, phi[j] *= (i - 1);
    scanf("%i", &T);
    while(T --)
    {
            scanf("%i", &X);
            printf("%lld\n", 1LL * 2 * X * phi[X]);
    }
    scanf("%i", &i);
    return 0;
}