标签:amp int scanf blank turn get href bre def
题面
https://www.luogu.org/problem/P2257
题解
#include<cstdio> #include<iostream> #define ri register int #define N 10000050 #define mxN 10000000 #define LL long long using namespace std; int T,n,m; int miu[N],g[N],p[N],pfk[N],prime[N/10]; LL sumg[N]; int main(){ scanf("%d",&T); pfk[1]=1;miu[1]=1; ri cnt=0; for (ri i=2;i<=mxN;i++) { if (!p[i]) { prime[++cnt]=i; pfk[i]=i; miu[i]=-1; } for (ri j=1;prime[j]*i<=mxN && j<=cnt;j++) { ri x=prime[j]*i; p[x]=prime[j]; pfk[x]=prime[j]; if (i%prime[j]==0) { pfk[x]*=pfk[i]; break; } } } for (ri i=2;i<=mxN;i++) if (p[i]) miu[i]=miu[pfk[i]]*miu[i/pfk[i]]; for (ri j=1;j<=cnt;j++) for (ri p=prime[j],i=1;i*p<=mxN;i++) g[i*p]+=miu[i]; for (ri i=1;i<=mxN;i++) sumg[i]=sumg[i-1]+g[i]; while (T--) { scanf("%d %d",&n,&m); int p=1,q=1; long long sum=0; ri i; for(int l=1,r;l<=min(n,m);l=r+1) { r=min(n/(n/l),m/(m/l)); sum+=1ll*(n/l)*(m/l)*(sumg[r]-sumg[l-1]); } //for (ri i=1;i<=n && i<=m;i++) sum+=g[i]*(n/i)*(m/i); printf("%lld\n",sum); } return 0; }
标签:amp int scanf blank turn get href bre def
原文地址:https://www.cnblogs.com/shxnb666/p/11427200.html