Cod sursa(job #1717983)

Utilizator SburlyAndrei Florin Sburly Data 16 iunie 2016 12:00:25
Problema Sum Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
/********************
    Created by Sburly
********************/
#include <fstream>

using namespace std;

#define inf 100000

long int n;
unsigned long int totient[inf+1];

int main()
{
    ifstream f("sum.in");
    ofstream g("sum.out");

    f >> n;

    for (unsigned long int i = 1; i < inf; ++i)
        totient[i] = i-1;
    for(unsigned long int i=2;i!=inf;i++)
        for(unsigned long int j=2;i*j<=inf;j++)
            totient[i*j]-=totient[i];

    for(unsigned long int i = n; i; --i)
    {
        long long int x;
        f >> x;
        g << 2*x*totient[x] << '\n';
    }

    return 0;
}