Pagini recente » Cod sursa (job #819146) | Cod sursa (job #2971825) | Cod sursa (job #3186747) | Cod sursa (job #2050860) | Cod sursa (job #4827)
Cod sursa(job #4827)
#define k 100000
#include "stdio.h"
FILE *f, *f2;
unsigned long long int a[k+1];
int n,x,i,j;
int main()
{
int i;
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;j*i<=k;j++)
a[i*j]=a[i*j]-a[i*j]/i;
}
}
f = fopen("sum.in","r");
fscanf(f, "%d\n", &n);
f2 = fopen("sum.out","w");
for(i=1;i<=n;i++)
{
fscanf(f, "%d\n", &x);
fprintf(f2, "%ld\n", 2*x*a[x]);
}
fclose(f);
fclose(f2);
return 0;
}