Cod sursa(job #2491736)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 13 noiembrie 2019 01:41:28
Problema Dreptunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
#include <cmath>

using namespace std;

ifstream fin("dreptunghiuri.in");
ofstream fout("dreptunghiuri.out");

long long Sol, N, M;

bool FindC(int A, int l, int L)///C^2 - LC + A(l - A) = 0
{
    int t = A * (l - A), delta, Ans = 0;

    if(L * L >= 4 * t)
        delta = sqrt(L * L - 4 * t);
    else
        return 0;

    if(delta * delta == L * L - 4 * t)
    {
        double c1 = (L + delta) / 2, c2 = (L - delta) / 2;

        if(0 < c1 && c1 < L && (L + delta) % 2 == 0)
            Ans++;

        if(0 < c2 && c2 < L && (L - delta) % 2 == 0)
            Ans++;

        return Ans;
    }
    return 0;
}

int Count(int l, int L)
{
    int Ans = 0;

    for(int A = 1; A < l; A++)
        Ans += FindC(A, l, L);

    return Ans + 1;
}

int main()
{
    fin >> N >> M;
    N--, M--;

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
        {
            Sol += Count(i, j) * (N - i + 1) * (M - j + 1);
        }
    fout << Sol << '\n';

    fin.close();
    fout.close();

    return 0;
}