Cod sursa(job #1207592)

Utilizator assa98Andrei Stanciu assa98 Data 13 iulie 2014 14:23:46
Problema Sum Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

const int MAX_N = 100000;

int c[MAX_N+10];

int main() {
    for(int i = 2; i <= MAX_N; i++) {
        c[i] = i;
    }

    for(int i = 2; i <= MAX_N; i++) {
        if(c[i] == i) {
            for(int j = i; j <= MAX_N; j += i) {
                c[j] *= i - 1;
                c[j] /= i;
            }
        }
    }
    
    int n;
    fin >> n;
    for(int i = 1; i <= n; i++) {
        long long x;
        fin >> x;
        fout << (long long)c[x] * 2 * x << '\n';
    }
    return 0;
}