Cod sursa(job #978174)

Utilizator Anca_PaneaPanea Anca Anca_Panea Data 28 iulie 2013 02:41:26
Problema Dreptunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
using namespace std;
#include<fstream>
ifstream eu("dreptunghiuri.in");
ofstream tu("dreptunghiuri.out");
# define Nmax 405
int M,N;
int Sqrt[Nmax*Nmax],h,w,sd,k,D,x1,x2;
long long Solutia;

void SQrT()
{
	for(int i=1;i<=N||i<=M;++i)
		Sqrt[i*i]=i;
}
int main()
{	eu>>N;
	eu>>M;
	N--;
	M--;
	SQrT();
	if(N>M)
		swap(N,M);
		for(h=1;h<=N;h++)
			for(w=1;w<=M;w++)
		{
			sd=0;
			for(k=0;k<h;k++)
			{
				int a=1 , b=-w , c=k*(h-k);
				D=b*b-4*a*c;
				if(D<0&&(D && !Sqrt[D]))
					continue;
				D=Sqrt[D];
				x1=(-b-D)/2;
				x2=(-b+D)/2;
				if((x1>=0&&x1<w&&(-b+D)%2==0)||(x2>=0&&x2<w&&(-b-D)%2==0&&x1!=x2))
					sd++;
			}
		Solutia+=(N-h+1)*(M-w+1)*sd;
		}
		tu<<Solutia;
		return 0;
}