Cod sursa(job #1585321)

Utilizator atatomirTatomir Alex atatomir Data 30 ianuarie 2016 22:17:58
Problema Dreptunghiuri Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 444

int n, m, i;
int how[maxN][maxN];
int a, b, c, d;
ll ans;

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

    scanf("%d%d", &n, &m);
    n--; m--;

    for (a = 1; a <= n; a++) {
        for (b = 1; b <= m; b++) {
            for (c = 1; b + c <= m; c++) {
                if ( (c * b) % a != 0 ) continue;
                d = (c * b) / a;

                if (d + a <= n) how[a + d][b + c]++;
            }
        }
    }

    for (a = 1; a <= n; a++)
        for (b = 1; b <= m; b++)
            ans += 1LL * (how[a][b] + 1) * (n - a + 1) * (m - b + 1);

    printf("%lld", ans);


    return 0;
}