Cod sursa(job #1173918)

Utilizator enedumitruene dumitru enedumitru Data 21 aprilie 2014 10:05:59
Problema Dreptunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<fstream>
#include<iostream>
using namespace std;
ifstream f("dreptunghiuri.in"); ofstream g("dreptunghiuri.out");
int m,n,w,h,a,b,r,x,y;
int nr;
int main()
{	f>>m>>n; 
	for(h=1;h<m;h++)
		for(w=1;w<n;w++)
		{	nr+=(m-h)*(n-w);
			//cout<<"* "<<h<<' '<<w<<" dim "<<(m-h)*(n-w)<<'\n';
			for(a=1;a<=h;a++)
			{	b=h-a;
				r=w*w-4*a*b;
				if(r>0)
				{	y=(int)sqrt((double)r);
					if(y*y==r)
					{	x=w-y;
						if(!(x&1) && x>0) nr++;
						x=w+y;
						if(!(x&1) && x/2<w) nr++;
					}
				}
				if(!r && !(w&1)) nr++;
			}
		}
	g<<nr<<'\n';	
	g.close(); return 0;
}