Cod sursa(job #1111884)

Utilizator teoionescuIonescu Teodor teoionescu Data 19 februarie 2014 10:50:53
Problema Sum Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
/*
n=p1^a1*p2^a2*...*pk^ak
phi(n) = n * (p1-1/p1) * ... * (pk-1/pk)
OBS: Pt p prim cu n => n-p,n+p prime cu n
*/
#include<fstream>
using namespace std;
ifstream in("sum.in");
ofstream out("sum.out");
const int Nmax = 100000;
int e[Nmax+100];
int T,N;
int main(){
    //for(int i=2;i<=Nmax;i++) e[i]=i;
    for(int i=2;i<=Nmax;i++){
        if(e[i]==0) e[i]=i;
        if(e[i]==i){
            for(int j=i;j<=Nmax;j+=i){
                if(e[j]==0) e[j]=j;
                e[j]=e[j]/i*(i-1);
            }
        }
    }
    in>>T;
    for(;T;--T){
        in>>N;
        out<<1LL*2*e[N]*N<<'\n';
    }
    return 0;
}