提交时间:2024-02-27 13:31:22
运行 ID: 26916
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned int uint; const int N = 2e5 + 9, M = 1e6 + 9, Mod = 1073741824; int _, n, m; uint d[M], d2[M], num[M], mu[M]; vector<int> pri; bitset<M> vis; void init() { d[1] = num[1] = mu[1] = 1; for (int i = 2; i <= 1e6; i++) { if (!vis[i]) { d[i] = 2, num[i] = 1, mu[i] = -1; pri.push_back(i); } for (int j : pri) { if (i * j > 1e6) break; vis[i * j] = 1; if (i % j == 0) { num[i * j] = num[i] + 1, mu[i * j] = 0; d[i * j] = d[i] / num[i * j] * (num[i * j] + 1); break; } d[i * j] = d[i] << 1, num[i * j] = 1, mu[i * j] = -mu[i]; } } } namespace Sub1 { void Main() { uint ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { ans += d[i * i] * d[j * j] * d[i * j]; } } printf("%u\n", ans % Mod); } } uint D2(uint n) { uint res = 0; for (int i = 1; i * i <= n; i++) { if (n % i) continue; res += mu[i] * d[n / i] * d[n / i]; if (i != n / i) res += mu[n / i] * d[i] * d[i]; } return res; } vector<uint> S[N]; namespace Sub2 { void Main() { uint res = 0; for (int p = 1; p <= n; p++) { res += mu[p] * S[p][n / p] * S[p][m / p]; } printf("%u\n", res % Mod); } } signed main() { init(); scanf("%d", &_); for (int i = 1; i <= 2e5; i++) d2[i] = D2(i); for (int p = 1; p <= 2e5; p++) { S[p].push_back(0); for (int i = 1; i <= (int)(2e5) / p; i++) { S[p].push_back(S[p][i - 1] + d2[i * p] * d[i]); } } while (_--) { scanf("%d%d", &n, &m); if (n > m) swap(n, m); if (n <= 1000 && m <= 1000) Sub1::Main(); else Sub2::Main(); } return 0; }