Cod sursa(job #1529682)
Utilizator | Chis Gabriel gabrielchis | Data | 21 noiembrie 2015 10:29:54 |
---|---|---|---|
Problema | Sum | Scor | 45 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc(int a,int b)
{
while(a!=b)
{
if(a>b) a=a-b;
else b=b-a;
}
return a;
}
int main()
{int x,i,k,n;
long long s;
ifstream f("sum.in");
ofstream g("sum.out");
f>>n;
for(k=1;k<=n;k++)
{
f>>x;
s=1;
for(i=2;i<2*x;i++)
{
if (cmmdc(i,x)==1) s=s+i;
}
g<<s<<"\n";
}
}