[SDOI2015]约数个数和
[SDOI2015]约数个数和
https://ac.nowcoder.com/acm/problem/20379
[SDOI2015]约数个数和
/* Author : lifehappy */ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e4 + 10; int prime[N], mu[N], cnt; bool st[N]; ll f[N]; void init() { mu[1] = 1; for(int i = 2; i < N; i++) { if(!st[i]) { prime[++cnt] = i; mu[i] = -1; } for(int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) { st[i * prime[j]] = 1; if(i % prime[j] == 0) { break; } mu[i * prime[j]] = -mu[i]; } } for(int i = 1; i < N; i++) { mu[i] = mu[i] + mu[i - 1]; for(int l = 1, r; l <= i; l = r + 1) { r = i / (i / l); f[i] += 1ll * (i / l) * (r - l + 1); } } } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); init(); int T; scanf("%d", &T); while(T--) { int n, m; scanf("%d %d", &n, &m); if(n > m) swap(n, m); ll ans = 0; for(int l = 1, r; l <= n; l = r + 1) { r = min(n / (n / l), m / (m / l)); ans += (mu[r] - mu[l - 1]) * f[n / l] * f[m / l]; } printf("%lld\n", ans); } return 0; }