Cod sursa(job #2811419)

Utilizator hhoangcpascalHa Van Hoang hhoangcpascal Data 2 decembrie 2021 11:23:51
Problema Dreptunghiuri Scor 100
Compilator cpp-64 Status done
Runda Lista lui wefgef Marime 0.71 kb
/// hhoangcpascal

#include <iostream>
#include <algorithm>
#include <cmath>
#define llong long long

using namespace std;

int m, n, ab[160006], cd[160006];

int main() {
    freopen("dreptunghiuri.in", "r", stdin);
    freopen("dreptunghiuri.out", "w", stdout);

    ios_base::sync_with_stdio(0); cin.tie(NULL);

    cin >> m >> n; --m, --n;
    llong ans = 1LL * m * (m + 1) * n * (n + 1) / 4;

    for(int a = 1; a < m; ++a)
    for(int b = 1; b + a <= m; ++b) ab[a*b] += (m - a - b + 1);

    for(int c = 1; c < n; ++c)
    for(int d = 1; c + d <= n; ++d) cd[c*d] += (n - c - d + 1);

    for(int i = 1; i <= min(n * n, m * m); ++i) ans += ab[i] * cd[i];

    cout << ans;

    return 0;
}