You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
586 B
24 lines
586 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define int long long
|
|
#define endl "\n"
|
|
|
|
// C(n,3)计算公式
|
|
int C(int n) {
|
|
return n * (n - 1) * (n - 2) / (3 * 2 * 1);
|
|
}
|
|
|
|
signed main() {
|
|
int n, m;
|
|
cin >> n >> m; // 行数,列数
|
|
n++, m++; // 将格子数转换成格点数,n->n+1,m->m+1
|
|
|
|
int res = C(n * m) - n * C(m) - m * C(n);
|
|
// 枚举所有高为i,宽为j的线段AB
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= m; j++)
|
|
res -= 2 * (__gcd(i, j) - 1) * (n - i) * (m - j);
|
|
|
|
printf("%lld\n", res);
|
|
}
|