Cod sursa(job #2787162)

Utilizator NopeCarp Rafael Nope Data 22 octombrie 2021 17:45:04
Problema Sum Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <bits/stdc++.h>
using namespace std;

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

int phi[100002] , n , x;

int main()
{
    int i , j;
    for(i = 1 ; i <= 100000 ; i++)
        phi[i] = i;
    for(i = 1 ; i <= 100000 ; i++)
        for(j = i * 2 ; j <= 100000 ; j += i)
            phi[j] -= phi[i];
    fin >> n;
    while(n--)
    {
        fin >> x;
        fout << 1LL*2*x*phi[x] << "\n";
    }
    return 0;
}