codeforces 1007B Pave the Parallelepiped
题意
题解
代码
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "
"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---
const int N = 101010, M = 166;
int a[3], cnt[8], d[N];
map<pair<pii, int>, bool> vis;
ll f[M], f2[N];
void init() {
rep(i, 1, M) {
rep(j, 1, i+1) f[i] += 1ll * j * (i - j + 1);
f2[i] = 1ll * i * (i+1) / 2;
}
rep(i, 1, N) {
for(int j = 1; j * j <= i; ++j) if(i%j==0) {
++d[i];
if(j != i/j) ++d[i];
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
init();
int T;
cin >> T;
while(T--) {
rep(i, 0, 3) cin >> a[i];
cnt[1] = d[a[0]];
cnt[2] = d[a[1]];
cnt[4] = d[a[2]];
cnt[3] = d[__gcd(a[0], a[1])];
cnt[5] = d[__gcd(a[0], a[2])];
cnt[6] = d[__gcd(a[1], a[2])];
cnt[7] = d[__gcd(__gcd(a[0], a[1]), a[2])];
cnt[3] -= cnt[7];
cnt[5] -= cnt[7];
cnt[6] -= cnt[7];
cnt[1] -= cnt[3] + cnt[5] + cnt[7];
cnt[2] -= cnt[3] + cnt[6] + cnt[7];
cnt[4] -= cnt[5] + cnt[6] + cnt[7];
ll ans = 0;
vis.clear();
rep(a, 1, 8) if(cnt[a] && (a&1)) rep(b, 1, 8) if(cnt[b] && (b>>1&1)) rep(c, 1, 8) if(cnt[c] && (c>>2&1)) {
int x[] = {a, b, c};
sort(x, x+3);
int i = x[0], j = x[1], k = x[2];
auto t = mp(mp(i, j), k);
if(vis[t]) continue;
vis[t] = 1;
if(i == j && i == k) {
ans += f[cnt[i]];
} else if(i == j) {
ans += f2[cnt[i]] * cnt[k];
} else if(i == k) {
ans += f2[cnt[i]] * cnt[j];
} else if(j == k) {
ans += f2[cnt[j]] * cnt[i];
} else {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
cout << ans << endl;
}
return 0;
}