Cod sursa(job #448833)

Utilizator HoriaClementHoriaC HoriaClement Data 4 mai 2010 20:24:17
Problema Sum Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <cstdio>

#define N 100005
int phi[1<<17],n,x;

void multiplu()
{
	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+=i) phi[j] /=i, phi[j] *= (i-1);
}
void rez()
{
	freopen("sum.in","r",stdin);
	freopen("sum.out","w",stdout);
	scanf("%d",&n);
	multiplu();
	for(int k=1;k<=n;++k)
	{
		scanf("%d",&x);
		printf("%d",(long long)phi[x]*x*2);
		printf("\n");
	}
}
int main()
{
	rez();
	return 0;
}