Cod sursa(job #342446)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 21 august 2009 19:12:32
Problema Dreptunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<cstdio>
#define N 400
short int n,m;
int delta,num,rez;
bool radical()
{
	for (int i=0; i*i<=delta; ++i)
		if (i*i==delta)
		{
			delta=i;
			return true;
		}
	return false;
}
void ecuatie(int h, int w)
{
	num=1;
	for (int a=2; a<h; ++a)
	{
		delta=w*w-4*a*(h-a);
		if (radical())
		{
			int c=(w-delta);
			if (c%2==0&&c/2>=2&&c/2<w)
				++num;
			else
			if (delta)
			{
				c=w+delta;
				if (c%2==0&&c/2>=2&&c/2<w)
				++num;
			}
		}
	}
}
void citire()
{
	freopen("dreptunghiuri.in","r",stdin);
	freopen("dreptunghiuri.out","w",stdout);
	scanf("%hd%hd",&m,&n);
	for (int i=2; i<=n; ++i)
	{
		/*ecuatie(i,i);
		rez+=num*(n-i+1)*(m-i+1);*/
		for (int j=2; j<=m; ++j)
		{
			ecuatie(i,j);
			rez+=num*(n-i+1)*(m-j+1);
		}
	}
	printf("%d",rez);
}
int main()
{
	citire();
	return 0;
}