Cod sursa(job #1529698)
Utilizator | Chis Gabriel gabrielchis | Data | 21 noiembrie 2015 10:39:37 |
---|---|---|---|
Problema | Sum | Scor | 35 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc(int a,int b)
{
int r;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
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";
}
}