Cod sursa(job #2456461)

Utilizator OctavianVasileVasileOctavian OctavianVasile Data 14 septembrie 2019 13:43:58
Problema Dreptunghiuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("dreptunghiuri.in");
ofstream fout ("dreptunghiuri.out");
#define NMAX 403
int n, m, cnt;
long long ans;
int Rad [NMAX * NMAX];
int main (){
    fin >> m >> n;
    for (int i = 1; i <= NMAX; i ++)
        Rad [i * i] = i;
    for (int x = 1; x < n; x ++){
        for (int y = 1; y < m; y ++) {
            cnt = 1;
            for (int A = 1; A < x; A ++) {
                int delta = y * y - 4 * A * (x - A);
                if (delta == 0 && y % 2 == 0)
                    cnt ++;
                else if ((delta > 0 && Rad [delta] != 0) && (y + Rad [delta]) % 2 == 0 && y > Rad [delta])cnt += 2;
            }
            ans += (long long)cnt * (n - x) * (m - y);
        }
    }
    fout << ans;
    return 0;
}