Cod sursa(job #978259)

Utilizator Anca_PaneaPanea Anca Anca_Panea Data 28 iulie 2013 15:13:10
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 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>>M;
	N--;M--;
	SQrT();
		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];
				if (((-b+D)%2!=0)||((-b+D)%2!=0))
                    continue;
				x1=(-b-D)/2;
				x2=(-b+D)/2;
				if(0<=x1 && x1<w)
					sd++;
				if(0<=x2 && x2<w && x1!=x2)
					sd++;
			}
		Solutia+=(N-h+1)*(M-w+1)*sd;
		}
		tu<<Solutia;
		return 0;
}