Cod sursa(job #2040704)

Utilizator syphuongcuong3Leo Aslan syphuongcuong3 Data 16 octombrie 2017 11:27:58
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.55 kb
#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a ; i <= b ; ++i)
#define FOD(i, a, b) for(int i = a ; i >= b ; --i)
#define FRSZ(i, a) for(int i = 0 ; i < a.size() ; ++i)
#define FDSZ(i, a) for(int i = a.size() - 1 ; i >= 0 ; --i)
#define debug(x) cout << #x << " = " << x << endl;
#define fi first
#define se second
#define MAXR 160001
using namespace std;

typedef int64_t ll;
int n, m;
int r[MAXR];

template <typename T> void Read(T &x){
	char ch;
	x = 0;
	do{ch = getchar();} while(!isdigit(ch));
	do{x = x * 10 + ch - 48; ch = getchar();} while(isdigit(ch));
	return;
}

template <typename T> void Write(T x){
	char a[32];
	int cnt = 0;
	do{a[++cnt] = x % 10 + 48; x /= 10;} while(x);
	FOD(i, cnt, 1) putchar(a[i]);
	return;
}

void InputData(){ Read(m); Read(n);}

void Init(){
	memset(r, -1, sizeof r);
	FOR(i, 1, 400 ) r[i * i] = i;
}

void MainProcess(){
	ll cnt, ans = 0;
	ll delta;
	FOR(i, 1, m - 1) //H
		FOR(j, 1, n - 1) {
			cnt = 0;
			FOR(k, 1, i - 1){ //a
				delta = j * j - 4 * k * (i - k);
				if (delta < 0) continue;
				if (delta == 0 && j % 2 == 0) {++cnt;continue;}
				if (r[delta] > 0 && (j - r[delta]) % 2 == 0) ++cnt;
				if (r[delta] > 0 && (j + r[delta]) % 2 == 0) ++cnt;
			}
			++cnt;
			// debug(i) debug(j) debug(cnt) cout << endl;

			ans += cnt * (m - i) * (n - j );
		}

	Write(ans);
}

int main(int argc, char const *argv[]) {

	freopen("dreptunghiuri.in", "r", stdin);
	freopen("dreptunghiuri.out", "w", stdout);

	InputData();
	Init();
	MainProcess();
	return 0;
}