Cod sursa(job #2780952)

Utilizator andreea_chivuAndreea Chivu andreea_chivu Data 8 octombrie 2021 10:19:44
Problema Sum Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

#define XMAX 100000

int e[XMAX + 1];

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

    int n;
    fin >> n;

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

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

    fin.close();
    fout.close();
    return 0;
}