Cod sursa(job #2128784)

Utilizator cella.florescuCella Florescu cella.florescu Data 12 februarie 2018 04:22:00
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Lista lui wefgef Marime 0.94 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 4e2;

int rad[MAXN * MAXN + 1];

int main()
{
    long long ans = 0LL;
    int n, m;
    ifstream fin("dreptunghiuri.in");
    fin >> n >> m;
    fin.close();
    for (int i = 1; i <= MAXN; ++i)
      rad[i * i] = i;
    for (int h = 1; h < n; ++h)
      for (int w = 1; w < m; ++w) {
        int loc_ans = 1;
        for (int lat = 1; lat < h; ++lat) {
          int delta = w * w - 4 * lat * (h - lat);
          if (delta == 0 && w % 2 == 0)
            ++loc_ans;
          else if (delta > 0 && rad[delta]) {
            if ((w + rad[delta]) % 2 == 0 && w > rad[delta])
              ++loc_ans;
            if ((w - rad[delta]) % 2 == 0 && w - rad[delta] >= 2)
              ++loc_ans;
          }
        }
        ans += 1LL * loc_ans * (n - h) * (m - w);
      }
    ofstream fout("dreptunghiuri.out");
    fout << ans;
    fout.close();
    return 0;
}