Cod sursa(job #982638)

Utilizator Dddarius95Darius-Florentin Neatu Dddarius95 Data 9 august 2013 16:32:15
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
#include <stdio.h>
#define Xmax 100009
using namespace std;
int n,phi[Xmax];

void GetPhi()
{
    for(int i=1;i<=Xmax;i++)phi[i]=i-1;
    for(int i=2;i<=Xmax;i++)
        for(int j=2*i;j<=Xmax;j+=i)phi[j]-=phi[i];
}

int main()
{

    ifstream f("sum.in");
    freopen("sum.out", "w", stdout);
    GetPhi();
    f>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        f>>x;
        long long sol=1LL*2*x*phi[x];
        printf("%lld\n",sol);
    }
    f.close();
    return 0;
}