标签:分块 using www. ++i eof lse bre else 就是
#include <bits/stdc++.h>
#define N 10000005
#define ll long long
#define getchar nc
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
inline void write(register ll x)
{
if(!x)putchar('0');if(x<0)x=-x,putchar('-');
static int sta[30];register int tot=0;
while(x)sta[tot++]=x%10,x/=10;
while(tot)putchar(sta[--tot]+48);
}
inline int Min(register int x,register int y)
{
return x<y?x:y;
}
int v[N],miu[N],prim[N],cnt=0,g[N];
ll sum[N];
int main()
{
miu[1]=1;
for(register int i=2;i<=N;++i)
{
if(!v[i])
{
miu[i]=-1;
prim[++cnt]=i;
}
for(register int j=1;j<=cnt&&prim[j]*i<=N;++j)
{
v[i*prim[j]]=1;
if(i%prim[j]==0)
break;
else
miu[prim[j]*i]=-miu[i];
}
}
for(register int i=1;i<=cnt;++i)
for(register int j=1;j*prim[i]<=N;++j)
g[j*prim[i]]+=miu[j];
for(register int i=1;i<=N;++i)
sum[i]=sum[i-1]+(ll)g[i];
int t=read();
while(t--)
{
int n=read(),m=read();
if(n>m)
n^=m^=n^=m;
ll ans=0;
for(register int l=1,r;l<=n;l=r+1)
{
r=Min(n/(n/l),m/(m/l));
ans+=(ll)(n/l)*(m/l)*(sum[r]-sum[l-1]);
}
write(ans),puts("");
}
return 0;
}
标签:分块 using www. ++i eof lse bre else 就是
原文地址:https://www.cnblogs.com/yzhang-rp-inf/p/10134439.html