Cod sursa(job #906181)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 6 martie 2013 16:17:20
Problema Dreptunghiuri Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <stdio.h>
#include <math.h>
using namespace std;

int N, M, R;

void cit ()
{
	scanf ("%d%d", &N, &M);
}

void pre ()
{
	int ix, iy, xs, delta, nr, sqi;
	double sq;
	
	for (ix = 1; ix <= N; ix++)
	{
		for (iy = 1; iy <= M; iy++)
		{
			nr = 1;
			for (xs = 1; xs < ix; xs++)
			{
				delta = iy * iy + 4 * xs * (xs - ix);
				if (delta <= 0)
				{
					if (delta == 0)
						nr++;
					continue;
				}
				
				sq = sqrt (delta);
				sqi = (int)sq;
				if (sq != sqi)
					continue;
				
				if (((iy + sqi) & 1) == 0)
					nr++;
				if (((iy - sqi) & 1) == 0)
					nr++;
			}
			
			if (ix < N && iy < M)
				R += nr * (N - ix) * (M - iy);
			/*
			if (ix <= M && iy <= N)
				R += nr * (M - ix + 1) * (N - iy + 1);
			*/
		}
	}
}

void afi ()
{
	printf ("%d", R);
}

int main ()
{
	freopen ("dreptunghiuri.in", "r", stdin);
	freopen ("dreptunghiuri.out", "w", stdout);
	
	cit ();
	pre ();
	afi ();
	
	return 0;
}