Cod sursa(job #914263)

Utilizator Marius96Marius Gavrilescu Marius96 Data 13 martie 2013 23:56:31
Problema Dreptunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<cstdio>

#define ok(x) ((x)%2==0 && (x)/2>=0 && (x)/2<w)

static int sqrt[405*405+5];

long long calc (int b,int c,int w)
{
	int d=b*b-4*c;
	int ret=0;
	if(d==0){
		if(ok (b))
			ret++;
	} else if(d>0 && sqrt[d]){
		if(ok (b-sqrt[d]))
			ret++;
		if(ok (b+sqrt[d]))
			ret++;
	}

	return ret;
}

int main (void)
{
	freopen ("dreptunghiuri.in","r",stdin);
#ifdef INFOARENA
	freopen ("dreptunghiuri.out","w",stdout);
#endif

	for(int i=1;i<=405;i++)
		sqrt[i*i]=i;
	
	int m,n;
	long long ret=0;
	scanf ("%d%d",&m,&n);
	for(int w=1;w<m;w++)
		for(int h=1;h<m;h++){
			for(int a=0;a<h/2;a++)
				ret+=calc (w,a*(h-a),w)*(m-w)*(n-h)*2;
			if(h%2==0)
				ret-=calc (w,h*h/4,w)*(m-w)*(n-h)*2;
				

	printf ("%lld",ret);
	return 0;
}