Cod sursa(job #2592447)
Utilizator | Daniel Popescu darkeagle | Data | 1 aprilie 2020 18:20:55 |
---|---|---|---|
Problema | Sum | Scor | 85 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <iostream>
#include <cstdio>
FILE * f = fopen("sum.in", "r");
FILE * g = fopen("sum.out", "w");
#define nmax 100005
using namespace std;
int n;
int phi[nmax];
int main() {
int i, j, x;
phi[1] = 0;
for ( i=1;i<=nmax;i++) phi[i]=i - 1;
for ( i=2;i<=nmax;i++) {
for(j = 2*i ;j <= nmax; j += i) {
phi[j] -= phi[i];
}
}
long long t;
fscanf(f,"%d", &n);
for (i = 1;i <= n;i++) {
fscanf(f,"%d",&x);
t = (long long)x * phi[x] * 2;
fprintf(g,"%lld\n",t);
}
fclose(f);
fclose(g);
return 0;
}