Sol
首先有个结论
∑mi=1∑nj=1d(i∗j)=∑mi=1∑nj=1∑x|i∑y|i[gcd(x,y)==1]
证明:可以看po姐的博客
接着这个式子推
原式=∑x=1n∑y=1m([gcd(x,y)==1]∗∑x|i∑y|i1)=∑x=1n∑y=1m[gcd(x,y)==1⌊nx⌋⌊my⌋]设f(i)=∑x=1n∑y=1m[gcd(x,y)==i⌊nx⌋⌊my⌋]设g(i)=∑x|df(d)
f(i)可以通过莫比乌斯反演求出
考虑求g(i)
g(i)=∑i|gcd(x,y)⌊nx⌋⌊my⌋=∑i|x∑i|y⌊nx⌋⌊my⌋=∑x=1⌊ni⌋∑y=1⌊my⌋⌊nx∗i⌋⌊my∗i⌋换个元=∑i=1x∑j=1y⌊xi⌋⌊yj⌋
这个东西 ∑xi=1⌊xi⌋ 就是每个数的倍数的个数和的和,就是每个数约数的个数和的和预处理一下,前缀和一下就好,于是每个g(i)就可以O(1) 求。。。(约数的个数是积性函数,也可以线性筛)
数论分块什么的就不说了
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(5e4 + 1);
IL ll Read(){
char c = '%'; ll x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
}
int prime[_], mu[_], d[_], pred[_], num;
bool isprime[_];
IL void Prepare(){
isprime[1] = 1; mu[1] = d[1] = 1;
for(RG int i = 2; i < _; ++i){
if(!isprime[i]){ prime[++num] = i; mu[i] = -1; d[i] = 2; pred[i] = 1; }
for(RG int j = 1; j <= num && i * prime[j] < _; ++j){
isprime[i * prime[j]] = 1;
if(i % prime[j]){ mu[i * prime[j]] = -mu[i]; d[i * prime[j]] = d[i] * 2; pred[i * prime[j]] = 1; }
else{
mu[i * prime[j]] = 0;
pred[i * prime[j]] = pred[i] + 1;
d[i * prime[j]] = d[i] / (pred[i] + 1) * (pred[i] + 2);
break;
}
}
d[i] += d[i - 1]; mu[i] += mu[i - 1];
}
}
int main(RG int argc, RG char *argv[]){
Prepare();
for(RG int T = Read(); T; --T){
RG int n = Read(), m = Read(); RG ll ans = 0;
if(n > m) swap(n, m);
for(RG int i = 1, j; i <= n; i = j + 1){
j = min(n / (n / i), m / (m / i));
ans += 1LL * (mu[j] - mu[i - 1]) * d[n / i] * d[m / i];
}
printf("%lld\n", ans);
}
return 0;
}