Cod sursa(job #595832)

Utilizator SebiSebiPirtoaca George Sebastian SebiSebi Data 14 iunie 2011 15:38:54
Problema Sum Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include<iostream.h>
#include<fstream.h>
int gcd(long a, long b) 
{ 
    
if (!b) return a; 
    
return gcd(b, a % b); 
}  

int main ()
{
	long a,b,x,i,n,s;
	ifstream f("sum.in");
	ofstream g("sum.out");
	f>>n;
	for(i=1;i<=n;i++) {
		f>>x;
		s=0;
		for(b=1;b<=2*x;b++) {
			a=x;
			if(gcd(a,b)==1) s=s+b;
		}
		g<<s<<'\n';
	}
	f.close();
	g.close();
	return 0;
}