Cod sursa(job #118165)

Utilizator DastasIonescu Vlad Dastas Data 23 decembrie 2007 12:25:30
Problema Sum Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>

const int maxn = 100001;

FILE *in = fopen("sum.in","r"), *out = fopen("sum.out","w");

int n;
int phi[maxn];

int main()
{
    fscanf(in, "%d", &n);

//    for (int i = 1; i <= maxn; ++i)
//        phi[i] = i-1;
//
//    for ( int i = 2; i <= maxn; ++i )
//        for ( int j = i << 1; j <= maxn; j += i )
//            phi[j] -= phi[i];

    for ( int i = 1; i <= maxn; i++ )
        phi[i]=i;

    for ( int i = 2; i<= maxn; i++ )
        if ( phi[i] == i )
            for ( int j = i; j <= maxn; j += i )
                phi[i] /= i, phi[i] *= (i-1);

    long long x;
    for ( int i = 1; i <= n; ++i )
    {
        fscanf(in, "%lld", &x);

        long long s = (long long)phi[x]*x*2LL;

        fprintf(out, "%lld\n", s);
    }

	return 0;
}