Cod sursa(job #2537279)

Utilizator nurof3nCioc Alex Andrei nurof3n Data 3 februarie 2020 15:15:01
Problema Sum Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 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(int N)
{
    for(int i = 1; i <= N; i++)
        totient[i] = i;
    for(int i = 2; i <= N; i += 2)
        totient[i] >>= 1;
    for(int i = 3; i <= N; i += 2)
        if(totient[i] == i)
            for(int j = i; j <= N; j += i)
                totient[j] = totient[j] / i * (i - 1);
}

int main()
{
    compute_totient2(N_MAX);
    int N, X;
    in >> N;
    while(N--)
    {
        in >> X;
        out << 2LL * X * totient[X] << '\n';
    }
    return 0;
}