Cod sursa(job #1857823)

Utilizator DanielRusuDaniel Rusu DanielRusu Data 26 ianuarie 2017 18:47:29
Problema Sum Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 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 << (long long)2 * (long long)phi[x] * (long long)x << '\n';
    }

    return 0;
}