Pagini recente » Cod sursa (job #294494) | Cod sursa (job #1340639) | Cod sursa (job #823255) | Cod sursa (job #1370658) | Cod sursa (job #1484517)
#include<stdio.h>
int n,m,i,j,k,x[9593],p[100001],t;
unsigned long long h[100001];
int main() {
freopen("sum.in","r",stdin),freopen("sum.out","w",stdout),x[++k]=2,h[2]=1;
for(i=1;((i*i)<<1)+(i<<1)<100001;i++)
if(!(p[i>>3]&(1<<(i&7))))
for(j=((i*i)<<1)+(i<<1);(j<<1)+1<100001;j+=(i<<1)+1)
p[j>>3]|=(1<<(j&7));
for(i=1;2*i+1<100001;++i)
if(!(p[i>>3]&(1<<(i&7))))
x[++k]=2*i+1,h[x[k]]=2*i;
for(i=2;i<100001;i++)
if(!h[i]) {
for(h[i]=j=i,t=1;x[t]*x[t]<=j&&j>1;t++)
if(j%x[t]==0)
for(h[i]=(h[i]/x[t])*(x[t]-1);j%x[t]==0;j/=x[t]);
if(j>1)
h[i]=(h[i]/j)*(j-1);
}
scanf("%d",&n);
while(n--)
scanf("%d",&m),printf("%llu\n",2*m*h[m]);
}