Cod sursa(job #1111886)

Utilizator teoionescuIonescu Teodor teoionescu Data 19 februarie 2014 10:53:05
Problema Sum Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 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 v[Nmax+5];
int e[Nmax+100];
int T,M;
int main(){
    in>>T;
    for(int i=1;i<=T;i++){
        in>>v[i];
        M=max(M,v[i]);
    }
    for(int i=2;i<=M;i++){
        if(e[i]==0) e[i]=i;
        if(e[i]==i){
            for(int j=i;j<=M;j+=i){
                if(e[j]==0) e[j]=j;
                e[j]=e[j]/i*(i-1);
            }
        }
    }
    for(int i=1;i<=T;i++){
        out<<1LL*2*e[v[i]]*v[i]<<'\n';
    }
    return 0;
}