Cod sursa(job #2132811)

Utilizator oldatlantianSerban Cercelescu oldatlantian Data 16 februarie 2018 02:05:01
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Lista lui wefgef Marime 0.61 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, n, m;

int main() {
	i64 x, y, u, v, l;

	fi >> n >> m;

	ant = n * (n - 1) * m * (m - 1) / 4;
	for (i64 tx = 1; tx < n; ++tx)
	for (i64 ty = 1; ty < m; ++ty) {
		x = tx / __gcd(tx, ty);
		y = ty / __gcd(tx, ty);

		u = n - tx;
		v = m - ty;

		l = min(u / y, v / x);

		if (l > 0) {
			ant+= l * u * v;
			ant-= l * (l + 1) / 2 * (u * x + v * y);
			ant+= l * (l + 1) * (2 * l + 1) / 6 * x * y; } }


	cerr << ant << endl;
	fo << ant << endl;

	return 0; }