Pagini recente » Cod sursa (job #4852) | Cod sursa (job #2980386) | Cod sursa (job #2991234) | Cod sursa (job #4646) | Cod sursa (job #4739)
Cod sursa(job #4739)
#define k 100000
#include "stdio.h"
FILE *f, *f2;
unsigned long a[k+1];
int n,x,i,j;
void 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(int j=2;i<=k/i;i++)
a[j*i] -= a[j*i] / 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", a[x]*2*x);
}
fclose(f);
fclose(f2);
}