Cod sursa(job #2132806)

Utilizator oldatlantianSerban Cercelescu oldatlantian Data 16 februarie 2018 01:36:09
Problema Dreptunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fi("dreptunghiuri.in");
ofstream fo("dreptunghiuri.out");

using i64 = long long;

const int N = 405;

i64 ant, l, n, m;

int main() {
	fi >> n >> m;

	ant = n * (n - 1) * m * (m - 1) / 4;
	for (i64 x = 1; x <= n; ++x)
	for (i64 y = 1; y <= m; ++y) if (x || y) {
		l = min((n - y) / x, (m - x) / y) - 1;
		if (l > 0) {
			ant+= l * (m * n - n * x - y * m + x * y);
			ant+= l * (l + 1) / 2 * (x * x + y * y - n * y - m * x);
			ant+= l * (l + 1) * (2 * l + 1) / 6 * x * y; } }

	fo << ant << endl;

	return 0; }