Pagini recente » Cod sursa (job #1915375) | Cod sursa (job #1058493) | Cod sursa (job #2755833) | Cod sursa (job #1453968) | Cod sursa (job #1723476)
#include <fstream>
#include <vector>
using namespace std;
const int N_MAX = 405;
const int INF = 0x3f3f3f3f;
int N, M;
int Roots[N_MAX];
int64_t Answer;
void getRoots() {
for(int i = 1; i < N_MAX; i++) {
if(!Roots[i]) Roots[i] = INF;
if(i * i < N_MAX) Roots[i * i] = i;
}
}
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 and D < N_MAX and Roots[D] != INF) {
D = Roots[D];
Count += (Width - D >= 0 and (Width - D) % 2 == 0);
Count += (Width + D <= 2 * Width and (Width + D) % 2 == 0);
if(!D) Count--;
}
}
return Count + 1;
}
int main() {
ifstream f("dreptunghiuri.in");
ofstream g("dreptunghiuri.out");
f >> N >> M;
getRoots();
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;
}