Cod sursa(job #35578)

Utilizator cromdioxidSasa Pastor cromdioxid Data 22 martie 2007 10:47:51
Problema Dreptunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#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;
}