Pagini recente » Cod sursa (job #146574) | Cod sursa (job #201753) | Cod sursa (job #1945844) | Cod sursa (job #444069) | Cod sursa (job #1723484)
#include <fstream>
using namespace std;
const int N_MAX = 405;
int N, M;
int Roots[N_MAX * N_MAX + 1];
int64_t Answer;
int getInscribedRectangles(int Height, int Width) {
int Count = 0;
for(int i = 1; i < Height; i++) {
int D = Width * Width - 4 * i * (Height - i);
if(D >= 0) {
int R = Roots[D];
if(R * R == D and ((Width - R) & 1) == 0) {
Count += (R == 0 ? 1 : 2);
}
}
}
return Count + 1;
}
int main() {
ifstream f("dreptunghiuri.in");
ofstream g("dreptunghiuri.out");
f >> N >> M;
for(int i = 1; i <= N_MAX; i++)
Roots[i] = i * i;
Answer = 0;
for(int i = 1; i < N; i++) {
for(int j = 1; j < M; j++) {
Answer += 1LL * getInscribedRectangles(i, j) * (N - i) * (M - j);
}
}
g << Answer << "\n";
return 0;
}