Cod sursa(job #1534202)

Utilizator george.stefanGeorge Stefan george.stefan Data 23 noiembrie 2015 14:46:17
Problema Sum Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int cmmdc(int a, int b)
{
    if (!b)
        return a;

    return cmmdc(b, a % b);
}

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

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, x;

    cin >> n;

    for(int j = 0; j < n; j ++)
    {
        cin >> x;

        long long suma = 0;

        for(int i = 1; i < 2 * x + 1; i ++)
        {
            if(i != x)
                if(cmmdc(i, x) == 1)
                    suma += i;
        }

        cout << suma << endl;
    }

    return 0;
}