Cod sursa(job #35657)

Utilizator MirceampMuresan Mircea Paul Mirceamp Data 22 martie 2007 11:52:02
Problema Sum Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>

using namespace std;

unsigned long int n, i, j;
unsigned long int x;
unsigned long int nr;
int cmmdc(int, int);


int main()
{
	ifstream fin("sum.in");
	ofstream fout("sum.out");


	fin >> n;

	for (i = 0; i < n; i++)
	{
		fin >> x;
		nr = 0;
		for (j = 0; j <= 2*x; j++)
			if (cmmdc(j, x) == 1)
				nr += j;
		fout << nr << "\n";
	}

	fin.close();
	fout.close();
	return 0;
}


int cmmdc(int a, int b)
{
	int r;

	while (a %b)
	{
		r = a %b;
		a = b;
		b = r;
	}
	return b;
}