Cod sursa(job #2711661)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 24 februarie 2021 16:04:18
Problema Dreptunghiuri Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <bits/stdc++.h>
#define int long long
#define sqr(x) ((x) * (x))

using namespace std;

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

const int VMAX = 1e5 + 6e4 + 1;
int N, M, rad[VMAX], ans;

int32_t main() {
    fin >> N >> M;
    for(int i = 1; i < VMAX; ++i)
        rad[i] = sqrt(i);
    for(int h = 1; h < N; ++h)
        for(int w = 1; w < M; ++w) {
            int cnt = 1;
            for(int k = 1; k < h; ++k) {
                int delta = sqr(w) - 4 * k * (h - k);
                if(delta == 0 && w % 2 == 0)
                    ++cnt;
                else
                    if(delta > 0 && delta == rad[delta] * rad[delta] && (w + rad[delta]) % 2 == 0 && w > rad[delta])
                        cnt += 2;
            }
            ans += cnt * (N - h) * (M - w);
        }
    fout << ans << '\n';
}