Cod sursa(job #1857822)
Utilizator | Data | 26 ianuarie 2017 18:46:37 | |
---|---|---|---|
Problema | Sum | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define DIM 100005
vector <int> phi;
int N, x;
void totient() {
for(int i = 2; i < DIM; ++i) {
phi[i] = i - 1;
}
for(int i = 2; i < DIM; ++i) {
for(int j = i * 2; j < DIM; j += i) {
phi[j] -= phi[i];
}
}
}
int main() {
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
phi.resize(DIM + 1);
totient();
scanf("%d\n", &N);
while(N--) {
scanf("%d\n", &x);
cout << 2 * phi[x] * x << '\n';
}
return 0;
}