Cod sursa(job #1620249)

Utilizator gorni97aaa aaa gorni97 Data 28 februarie 2016 22:26:58
Problema Sum Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;

int cmmdc(int x,int y)
{
    while((x!=y)&&((x>1)||(y>1)))
    {if(x>y)
    x=x-y;
    else
        y=y-x;}


    if(x==1)
        return 1;
    return x;
}


int main()

{int i,j,n,x;
long long s;
char v[200002];
fstream f("sum.in",ios::in);
fstream g("sum.out",ios::out);
f>>n;


    for(j=1;j<=n;j++)
    {f>>x;
    s=0;

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

g<<s<<'\n';
}

g.close();
f.close();

}