Pagini recente » Cod sursa (job #1753029) | Cod sursa (job #1564429) | Cod sursa (job #2771823) | Cod sursa (job #342059) | Cod sursa (job #35578)
Cod sursa(job #35578)
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int N, M, nr;
void ecuatie(int a, int b, int c, int &x1, int &x2)
{
double delta;
int delta1;
delta = b*b - 4*a*c;
if (delta < 0)
{
x1 = x2 = 500; return;
}
delta = sqrt(delta);
delta1 = (int) delta;
if (delta1 * delta1 != b*b - 4*a*c)
{
x1 = x2 = 500; return;
}
if ((-b-delta1) % (2*a))
x1 = 500;
else
x1 = (-b-delta1) / (2*a);
if ((-b+delta1) % (2*a))
x2 = 500;
else
x2 = (-b+delta1) / (2*a);
}
int main()
{
int h, w, a, x1, x2;
freopen("dreptunghiuri.in", "rt", stdin);
freopen("dreptunghiuri.out", "wt", stdout);
scanf("%d %d", &N, &M);
N--, M--;
nr = 0;
for (h = 1; h <= N; h++)
for (w = 1; w <= M; w++)
for (a = 1; a <= h; a++)
{
ecuatie(1, -w, a*h-a*a, x1, x2);
if (x1 >=1 && x1 <= w || x2 >= 1 && x2 <= w)
nr += (N - h +1) * (M - w + 1);
}
printf("%d\n", nr);
return 0;
}