Cod sursa(job #2736997)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 4 aprilie 2021 12:09:26
Problema Dreptunghiuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <bits/stdc++.h>

using namespace std;

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

const int VTMAX(160010);
int rad[VTMAX];

int main()
{
    int n, m;
    fin >> n >> m;

    for(int i = 1; i <= VTMAX - 5; ++i)
        rad[i] = sqrt(i);

    long long rez = 0;
    for(int h = 1; h < n; ++h)
        for(int w = 1; w < m; ++w)
        {
            int cnt = 1;
            for(int a = 1; a < h; ++a){
                int dlt = w * w - 4 * a * (h - a);
                if(dlt == 0 && w % 2 == 0)
                    ++cnt;
                else if(dlt > 0 && dlt == rad[dlt] * rad[dlt] && (w + rad[dlt]) % 2 == 0 && w > rad[dlt])
                    cnt += 2;
            }
            rez += 1LL * cnt * (n - h) * (m - w);
        }
    fout << rez << '\n';
    return 0;
}