Cod sursa(job #719531)

Utilizator w3.playerCostescu Ionut w3.player Data 21 martie 2012 20:59:35
Problema Sum Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <iostream>
using namespace std;
int n,x,i,y,cx,cy,s,ok;

int main()
{
	ifstream inFile("sum.in");
	inFile >> n;
	ofstream outFile("sum.out");
	for (i=0; i<n; i++)
	{
		inFile >> x;
		s=0; ok=1;
		for (y=2; ok==1 && y<=x/2; y++)
			if (x%y==0)
				ok=0;
		if (ok==1)
			for (y=1; y<x; y++)
				s+=y+y+x;
		else
			for (y=1; y<=x/2; y++)
			{
				cx=x; cy=y;
				while (cx!=0 && cy!=0)
					if (cx>cy)
						cx%=cy;
					else
						cy%=cx;
				if (cx==1 || cy==1)
					s+=4*y+2*(x/2+x);
			}
		outFile << s << "\n";
	}
	inFile.close();
	outFile.close();
	return 0;
}