Cod sursa(job #877727)

Utilizator dariusmareCostolas Darius dariusmare Data 13 februarie 2013 08:45:13
Problema Sum Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
int gcd(int a, int b)
{
    int t;
    while (b != 0)
    {
        t = b;
        b = a % b;
        a = t;
    }
    return a;

}

int main()
{
    ifstream in("sum.in");
    ofstream out("sum.out");
    long N,X;
    in >> N;

    for(int i=0; i<N; i++)
    {
        long long s=0;
        in >> X;
        for(int j=1; j<=2*X; ++j)
        {
            if(gcd(j,X) == 1) s+=j;
        }
       out << s << "\n";
    }
    return 0;
}