显示代码纯文本
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<time.h>
using namespace std;
int vis[10000001],F[10000001],miu[10000001],pri[10000001],cnt,t,n,m;
void INIT()
{
miu[1]=1;
for(int i=2;i<=10000000;i++)
{
if(!vis[i])
{
pri[++cnt]=i;
miu[i]=-1;
}
for(int j=1;j<=cnt;j++)
{
if(pri[j]*i>10000000)
break;
vis[pri[j]*i]=1;
if(i%pri[j]==0)
{
break;
}
miu[pri[j]*i]=-miu[i];
}
}
for(int i=1;i<=cnt;i++)
{
for(int j=1;j*pri[i]<=10000000;j++)
{
F[j*pri[i]]+=miu[j];
}
}
for(int i=1;i<=10000000;i++)
{
F[i]+=F[i-1];
}
}
long long Solve()
{
long long ans=0;
for(int l=1,r;l<=min(n,m);l=r+1)
{
r=min(n/(n/l),m/(m/l));
ans+=(long long)(F[r]-F[l-1])*(n/l)*(m/l);
}
return ans;
}
signed main()
{
freopen("YYnoGCD.in","r",stdin);
freopen("YYnoGCD.out","w",stdout);
scanf("%d",&t);
INIT();
while(t--)
{
scanf("%d%d",&n,&m);
printf("%lld\n",Solve());
}
return 0;
}