Cod sursa(job #2920408)

Utilizator bem.andreiIceman bem.andrei Data 24 august 2022 09:40:26
Problema Dreptunghiuri Scor 90
Compilator cpp-64 Status done
Runda Lista lui wefgef Marime 0.89 kb
#include <bits/stdc++.h>

using namespace std;
ifstream r("dreptunghiuri.in");
ofstream w("dreptunghiuri.out");
int n, m, cnt;
long long ans;
int rad[160005];
int main()
{
    r >> n >> m;
    for(int i = 1; i <= 160000; i++){
        rad[i] = sqrt(i);
    }
    for(int i = 1; i < n; i++)
    {
        for(int j = 1; j < m; j++)
        {
            cnt = 1;
            for(int a = 1; a < i; a++)
            {
                int delta = j * j - 4 * a * (i - a);
                if(delta == 0 && j % 2 == 0){
                    cnt++;
                }
                else
                {
                    if(delta > 0 && rad[delta] * rad[delta] == delta && (j + rad[delta]) % 2 == 0 && j > rad[delta])
                        cnt += 2;
                }
            }
            ans += cnt * (n - i) * (m - j);
        }
    }
    w<< ans;
    return 0;
}