Cod sursa(job #601855)

Utilizator ooctavTuchila Octavian ooctav Data 8 iulie 2011 00:28:03
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Lista lui wefgef Marime 1.53 kb
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<vector>
using namespace std;

const char IN[] = {"dreptunghiuri.in"};
const char OUT[] = {"dreptunghiuri.out"};
const int INF = 1000000005;
const double PI  = 3.14159265;
const int NMAX = 405;

#define II inline
#define LL long long
#define PII pair<int, int>
#define PDD pair<double, double>
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) 	for(int i = a ; i <= b ; i++)
#define IFOR(i, a, b) 	for(int i = a ; i >= b ; i--)
#define FORIT(it, V) 	for(vector<int> :: iterator it = V.begin() ; it != V.end() ; it++)
#define all(a) a, a + 

int N, M;
LL REZ;
int patrat[NMAX*NMAX];

void patrate_perfecte()
{
	if(N < M)	swap(N, M);
	
	int lim = N;
	FOR(i, 0, lim)
		patrat[i*i] = i;
}

void numara()
{
	N--; M--;
	
	FOR(l, 1, N)
		FOR(h, 1, M)
			FOR(a, 1, h)
			{
				int dt;
				dt = l*l + 4*a*a - 4*h*a;
				if(dt < 0 || dt > N*N || (!patrat[dt] && dt))	continue;
				dt = patrat[dt];
				if((l - dt)&1 && (l + dt)&1)	continue;
				
				int x1 = (l - dt)>>1, x2 = (l + dt)>>1;
				if(x1 && x1 <= l)
					REZ += (N - l + 1)*(M - h + 1);
				if(x1 != x2 && x2 && x2 <= l)
					REZ += (N - l + 1)*(M - h + 1);
			}
}

int main()
{
	freopen(IN, "r", stdin);
	freopen(OUT, "w", stdout);
	scanf("%d%d", &N, &M);
	patrate_perfecte();
	numara();
	printf("%lld\n", REZ);
	return 0;
}