My approach is based on two formulas:
\ [[n-=. 1] = \ sum_ {D | n-} \ MU (D) \]
\ [\ sigma_0 (I * J) = \ sum_ {X | I} \ sum_ {Y | J} [GCD (X , y) = 1] \]
wherein \ (\ sigma_0 (n) \ ) represents \ (n-\) number divisors
The first formula is a function of the basic properties of Mobius, as demonstrated in the second formula, could be considered \ (i * j \) in each of the prime factors of \ (\ sigma_0 (i * j ) \) contributed for a quality factor \ (P \) , if it is in \ (I \) number in the range \ (k_1 \) , it \ (J \) number in the range \ (K_2 \) , then \ ( \ sigma_0 (i * j) \ ) in \ (P \) contribution \ ((k_1 + + K_2. 1) \) (about a few number of formulas), in \ (gcd (x, y) = 1 \) in the case where either \ (X \) in \ (P \) number is 0, or \ (Y \) in \ (P \) number is 0, a total of \ ((k_1 + k_2 + 1 ) \) kinds of programs, and \ (i * j \) the same contribution, so the equation is equal to the left and right sides.
Then you can push a pleasant expression it!
\[ \sum_{i=1}^{n} \sum_{j=1}^{m}\sigma_0(i*j)\]
\[ \sum_{i=1}^{n} \sum_{j=1}^{m}\sum_{x|i}\sum_{y|j}[gcd(x,y)=1]\]
\[\sum_{x=1}^{n}\sum_{y=1}^m \sum_{i=1}^{\lfloor \frac{n}{x} \rfloor } \sum_{j=1}^{\lfloor \frac{m}{y}\rfloor} [gcd(x,y)=1]\]
\[\sum_{x=1}^{n}\sum_{y=1}^m \lfloor \frac{n}{x} \rfloor \lfloor \frac{m}{y}\rfloor \sum_{k|gcd(x,y)}\mu(k)\]
\[\sum_{k=1}^{n}\sum_{x=1}^{\lfloor \frac{n}{k}\rfloor}\sum_{y=1}^{\lfloor \frac{m}{k} \rfloor} \lfloor \frac{n}{kx}\rfloor \lfloor \frac{m}{ky} \rfloor\mu(k)\]
\[\sum_{k=1}^{n}\mu(k)(\sum_{x=1}^{\lfloor \frac{n}{k}\rfloor}\lfloor\frac{n}{kx}\rfloor)(\sum_{y=1}^{\lfloor\frac{m}{k}\rfloor}\lfloor\frac{m}{ky}\rfloor)\]
Then we set \ (S (n-) = \ sum_ {I =. 1} ^ {n-} \ lfloor \ FRAC {n-} {I} \ rfloor \) , apparently \ (S (n) \) is \ (O (\ sqrt {n}) \ ) calculated
Then the above equation can be turned into:
\[\sum_{k=1}^{n}\mu(k)S(\lfloor\frac{n}{k}\rfloor)S({\lfloor\frac{m}{k}\rfloor})\]
First Pretreatment \ (S (. 1) -S (MAXN) \) , then you can \ (O (\ sqrt {n }) \) to answer each inquiry it!
Code:
#include<bits/stdc++.h>
using namespace std;
#define N 50007
#define ll long long
const int lim=50000;
ll s[N];
int ui[N],pr[N],cnt;
bool zhi[N];
void Init()
{
int i,j;
ui[1]=1;
for(i=2;i<=lim;i++)
{
if(!zhi[i])
{
pr[++cnt]=i;
ui[i]=-1;
}
for(j=1;j<=cnt&&i*pr[j]<=lim;j++)
{
int p=pr[j],x=i*p;
zhi[x]=true;
if(i%p==0)
{
ui[x]=0;
break;
}
ui[x]=-ui[i];
}
}
for(i=1;i<=lim;i++)
ui[i]+=ui[i-1];
for(i=1;i<=lim;i++)
{
int l,r;
for(l=1;l<=i;l=r+1)
{
r=i/(i/l);
s[i]+=1ll*(r-l+1)*(i/l);
}
}
}
int main()
{
int n,m,t;
Init();
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
int l1=1,r1,l2=1,r2,cur=1;
ll ans=0;
while(l1<=n&&l2<=m)
{
int l,r;
r1=n/(n/l1),r2=m/(m/l2);
l=cur;
if(r1<r2)r=r1,cur=l1=r1+1;
else r=r2,cur=l2=r2+1;
ans+=1ll*(ui[r]-ui[l-1])*s[n/l]*s[m/l];
}
printf("%lld\n",ans);
}
return 0;
}