Cod sursa(job #1529651)

Utilizator gabrielchisChis Gabriel gabrielchis Data 21 noiembrie 2015 09:55:34
Problema Sum Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <iostream>
#include <fstream>
using namespace std;
int x,s=0,n,i,j;
int cmmdc(int a,int b)
{
    while(a!=b)
    {
        if(a>b) a=a-b;
        if(b>a) b=b-a;
    }
    return a;
}
int main()
{
    ifstream f("sum.in");
    ofstream g("sum.out");
    f>>n;
    for(j=0;j<n;j++)
    {
        f>>x;
        for(i=1;i<2*x;i++)
        {
            if (cmmdc(i,x)==1) s=s+i;
        }
        g<<s<<endl;
        s=0;
    }
}