Cod sursa(job #992361)

Utilizator andreiblaj17Andrei Blaj andreiblaj17 Data 1 septembrie 2013 18:15:17
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <fstream>
#include <stdio.h>
#define nmax 100001

using namespace std;

long long phi[nmax];
int n,x;

int main()
{
    ifstream f("sum.in");
    freopen("sum.out", "w", stdout);

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

    f >> n;
    while (n--){
        f >> x;
        long long s=x*phi[x]*2;
        printf("%lld\n",s);
    }

    return 0;
}