Cod sursa(job #921153)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 20 martie 2013 20:08:29
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<fstream>
using namespace std;

long long i,j,x,y,a,b,n,s;

int gcd(int x,int y)
{
	int r;
	while (y>0)
	{
		r=x%y;
		x=y;
		y=r;
	}
	return x;
}

int main()
{
	ifstream f("dreptunghiuri.in");
	ofstream g("dreptunghiuri.out");
	f >> x >> y;
	for (i=1;i<=x;i++)
		for (j=0;j<=y;j++)
			if (gcd(i,j)==1)
				for (a=1;a*i<=x;a++)
					for (b=1;(a*i+b*j<=x) && (a*j+b*i<=y);b++)
						s+=(x-a*i-b*j)*(y-a*j-b*i);
	g << s;
	return 0;
}