Cod sursa(job #1479495)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 31 august 2015 15:06:56
Problema Sum Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMax = 1e5 + 5;

int v[NMax];

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