Pagini recente » Cod sursa (job #819263) | Cod sursa (job #2213003)
#include <stdio.h>
#define MAX 100000
int phi[MAX + 1];
inline void calc_phi(){
for(int i = 2; i <= MAX; i++)
phi[i] = i;
for(int i = 2; i <= MAX; i++)
if(phi[i] == i)
for(int j = i; j <= MAX; j += i)
phi[j] = phi[j] / i * (i - 1);
}
int main(){
int x, N;
freopen("sum.in", "r", stdin);
freopen("sum.out", "w", stdout);
scanf("%d", &x);
calc_phi();
for(int i = 0; i < x; i++){
scanf("%d", &N);
printf("%lld\n", (long long)phi[N] * 2 * N);
}
return 0;
}