题意:略
然后线性筛预处理,分块搞定
#include <bits/stdc++.h>
#define gc getchar()
#define N 100009
#define ll long long
using namespace std;
int T,n,m,pri[N],pd[N],cnt,mu[N],Min[N];
ll ans,d[N];
int read()
{
int x=1;
char ch;
while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
int s=ch-48;
while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-48;
return s*x;
}
int main()
{
pd[d[1]=mu[1]=1]=1;
for (int i=2;i<N;i++)
{
if (!pd[i]) pri[++cnt]=i,mu[i]=-1,d[i]=2,Min[i]=1;
for (int j=1;j<=cnt&&pri[j]*i<N;j++)
{
pd[pri[j]*i]=1;
if (i%pri[j]==0)
{
Min[pri[j]*i]=Min[i]+1;
d[pri[j]*i]=d[i]/Min[pri[j]*i]*(Min[i]+2);
mu[pri[j]*i]=0;
break;
}
mu[pri[j]*i]=-mu[i];
Min[pri[j]*i]=1;
d[pri[j]*i]=d[i]*2;
}
}
for (int i=2;i<N;i++) d[i]+=d[i-1],mu[i]+=mu[i-1];
T=read();
while (T--)
{
ans=0;
n=read(),m=read();
if (n>m) swap(n,m);
for (int i=1,j;i<=n;i=j+1)
{
j=min(n/(n/i),m/(m/i));
ans+=(ll)(mu[j]-mu[i-1])*d[n/i]*d[m/i];
}
printf("%lld\n",ans);
}
return 0;
}