Cod sursa(job #2145544)

Utilizator ioana_marinescuMarinescu Ioana ioana_marinescu Data 27 februarie 2018 13:48:40
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <bits/stdc++.h>
const int MAX_N = 100005;

using namespace std;

ifstream fin("sum.in");
ofstream fout("sum.out");

long long phi[MAX_N];

int main()
{
    long long t, n, i, j;
    fin>>t;
    for(i=1; i<=MAX_N; i++)
        phi[i]=i;
    for(i=2; i<=MAX_N; i++)
       if(phi[i]==i)
         for(j=i; j<=MAX_N; j+=i)
           phi[j]=phi[j]*(i-1)/i;
    while(t--) {
        fin>>n;
        fout<<1LL*2*n*phi[n]<<'\n';
    }
    return 0;
}