hdu6715 发表于 2019-08-30 | 阅读数 次 链接:hdu6715 题解12345678910111213141516171819202122232425262728293031323334353637383940#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<algorithm>#define rep(i,x,y) for(register int i=x;i<=y;++i)#define repd(i,x,y) for(register int i=x;i>=y;--i)#define ll long longusing namespace std;const int N=2e6+7;ll mu[N],p[N],vis[N],cnt,n,m,T,a[N];ll ans;void get_mu(int n){ mu[1]=1; rep(i,2,n){ if(!vis[i])mu[i]=-1,p[++cnt]=i; for(int j=1;j<=cnt&&i<=n/p[j];++j){ vis[i*p[j]]=1; if(i%p[j]==0)break; mu[i*p[j]]-=mu[i]; } } rep(i,1,n)for(int j=i;j<=n;j+=i)a[j]+=mu[i]*mu[j/i];}int main(){ scanf("%d",&T); get_mu(1e6+7); while(T--&&~scanf("%d%d",&n,&m)){ if(n>m)swap(n,m); ans=0; rep(i,1,n){ int b=0,c=0; for(int j=i;j<=n;j+=i)b+=mu[j]; for(int j=i;j<=m;j+=i)c+=mu[j]; ans+=a[i]*b*c; } printf("%lld\n",ans); } return 0;}