Cod sursa(job #820388)

Utilizator SmarandaMaria Pandele Smaranda Data 20 noiembrie 2012 19:47:20
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <cstdio>
#define NMAX 100001

using namespace std;

long phi [NMAX];

void Preg () {
    long i , j;
    for (i = 2 ; i <= NMAX ; i ++)
        phi [i] = i;
    for (i = 2 ; i <= NMAX ; i ++)
        if (phi [i] == i)
            for (j = i ; j <= NMAX ; j = j + i)
                phi [j] = phi [j] / i * (i - 1);
}

int main () {
    long Tests , testcase , x;

    freopen ("sum.in" , "r" , stdin);
    freopen ("sum.out" , "w" , stdout);

    Preg ();
    scanf ("%ld" , &Tests);
    for (testcase = 1 ; testcase <= Tests ; testcase ++) {
        scanf ("%ld" , &x);
        printf ("%lld\n" , (long long)phi [x] * x * 2);
    }
    return 0;
}