Cod sursa(job #3359667)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 1 iulie 2026 17:41:12
Problema Dreptunghiuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>

using namespace std;

#define USE_STD_IO 0
#if USE_STD_IO
    #define fin cin
    #define fout cout
#else
    ifstream fin("dreptunghiuri.in");
    ofstream fout("dreptunghiuri.out");
#endif

const int MAXD = 400;
long long n, m, i, j, k, nr, d, r, rasp;
int rad[MAXD * MAXD + 2];

int main() {
    #if USE_STD_IO
        ios_base::sync_with_stdio(false);
    #endif // USE_STD_IO
    fin.tie(NULL);
    fout.tie(NULL);

    fin >> n >> m;
    for(i = 1; 400 >= i; i++) rad[i * i] = i;
    for(i = 1; i < n; i++) {
        for(j = 1; j < m; j++) {

            nr = 1;
            for(k = 1; k < i; k++) {
                d = j * j - 4 * k * (i - k);
                r = rad[d];

                if(0 == d && !(1 & j)) nr++;
                if(0 < d && 0 != r && !(1 & (j + r)) && r < j) {
                    nr += 2;
                }
            }
            rasp += nr * (n - i) * (m - j);
        }
    }
    fout << rasp;

    return 0;
}