Cod sursa(job #2779983)

Utilizator Razvan_GabrielRazvan Gabriel Razvan_Gabriel Data 5 octombrie 2021 17:38:35
Problema Sum Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>

using namespace std;

int e[100001];

void euler(int n){
    for(int i = 2; i <= n; i++)
        e[i]=i;
    for(int i = 2; i <= n; i++){
        if(e[i] == i){
            for(int j = i; j <= n; j += i)
                e[j] = e[j] / i * (i - 1);
        }
    }
}


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

    int n;
    fin >> n;

    euler(100000);

    for(int cnt = 0; cnt < n; cnt++){
        int x;
        fin >> x;
        fout << ((long long)e[x]) * x * 2 << "\n";
    }

    return 0;
}