Cod sursa(job #1777824)

Utilizator CiurezAndreiCiurez Marius-Andrei CiurezAndrei Data 12 octombrie 2016 22:04:33
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <bits/stdc++.h>

using namespace std;

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

int N, testCount, X, solution;
int v[100010];
char c;

inline int get_nr()
{
    int number = 0;

    c = getc(stdin);

    while(!isdigit(c))
    {
        c = getc(stdin);
    }

    while (isdigit(c))
    {
        number = number * 10 + c - '0';
        c = getc(stdin);
    }

  return number;
}

int main()
{
    freopen("sum.in", "r", stdin);

    //fin >> testCount;
    testCount = get_nr();

    for(int i = 1; i <= 100000; i ++)
    {
        v[i] = i;
    }

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

    while(testCount --)
    {
        //fin >> X;
        //fscanf(stdin,"%d", &X);
        X = get_nr();
        unsigned long long solution = 1LL * X * v[X] * 2;
        fout << solution << '\n';
    }

    return 0;
}