Cod sursa(job #2244714)

Utilizator nurof3nCioc Alex Andrei nurof3n Data 23 septembrie 2018 15:05:45
Problema Sum Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>

using namespace std;

ifstream in("sum.in");
ofstream out("sum.out");

const int N_MAX = 100000;
int totient[N_MAX + 1], X[N_MAX + 1];

void compute_totient2(int N) {
    for(int i = 1; i <= N; i++)
        totient[i] = i;
    for(int i = 2; i <= N; i++)
        if(totient[i] == i)
            for(int j = i; j <= N; j += i)
                totient[j] -= totient[j] / i;
}

int main()
{
    int N, X_max = 0;
    in >> N;
    for(int i = 1; i <= N; i++) {
        in >> X[i];
        X_max = max(X_max, X[i]);
    }
    compute_totient2(X_max);
    for(int i = 1; i <= N; i++)
        out << 1LL * 2 * totient[X[i]] * X[i] << '\n';
    return 0;
}