Cod sursa(job #2244710)

Utilizator nurof3nCioc Alex Andrei nurof3n Data 23 septembrie 2018 15:02:53
Problema Sum Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>

using namespace std;

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

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

void compute_totient2(const 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()
{
    compute_totient2(N_MAX);
    int N, X;
    in >> N;
    for(int i = 1; i <= N; i++) {
        in >> X;
        out << 2 * totient[X] * X << '\n';
    }
    return 0;
}