Cod sursa(job #270149)

Utilizator mihnea_andreiMihnea Andrei mihnea_andrei Data 3 martie 2009 19:41:16
Problema Sum Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include<fstream> 
#define N 100001 

using namespace std; 

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

int x[N],n; 
long long phi[N]; 

void citire () 
{ 
	in>>n; 
	for(int i=1;i<=n;i++) 
		in>>x[i]; 
} 

void calcul () 
{ 
	for(int i=1;i<=N;i++) 
		phi[i]=i; 
	for(int i=2;i<=N;i++) 
	{ 
		if(phi[i]==i) 
		{ 
			for(int j=i;j<=N;j=j+i) 
				phi[j]=(phi[j]/i)*(i-1);
		}
	}
}

int main () 
{ 
	citire (); 
	calcul (); 
	for(int i=1;i<=n;i++) 
		out<<2*x[i]*phi[x[i]]<<endl; 
	in.close (); 
	out.close (); 
	return 0; 
}