Cod sursa(job #914307)

Utilizator Marius96Marius Gavrilescu Marius96 Data 14 martie 2013 00:55:46
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<cstdio>

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

static short sqrt[405*405+5];

int _calc (int b,int c)
{
	int d=b*b-4*c;

	if(d==0)
		return ok (b);
	else if(d>0 && sqrt[d])
		return ok (b-sqrt[d]) + ok (b+sqrt[d]);
	return 0;
}
#define calc(a) _calc (w, (a)*(h-(a)))*(m-w)*(n-h)

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<n;h++){
			for(int a=0;a<=h/2;a++)
				ret+=calc (a)*2;
			if(h%2==0)
				ret-=calc (h/2);
			ret-=calc (h);
		}

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