Cod sursa(job #2213003)

Utilizator Fantastic_Mantudor voicu Fantastic_Man Data 15 iunie 2018 15:37:08
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#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;
}