Pagini recente » star_trek | Cod sursa (job #2867569) | Cod sursa (job #2053729) | Cod sursa (job #2071237) | Cod sursa (job #4843)
Cod sursa(job #4843)
#define k 100000
#include <stdio.h>
int main(){
unsigned long long a[k+1];
long i,j,n;
FILE *f,*f2;
f=fopen("sum.in","r");
f2=fopen("sum.out","w");
for (i=2;i<=k;i++) a[i]=i;
for (i=2;i<=k;i++)
if (a[i]==i) {
a[i]=i-1;
for (j=2;i*j<=k;j++) a[i*j]-=a[i*j]/i;
}
fscanf(f,"%ld",&n);
for (i=1;i<=n;i++) {
fscanf(f,"%ld",&j);
fprintf(f2,"%ld\n",a[j]*j*2);
}
fclose(f);
fclose(f2);
}