标签:lin 函数 mat prim int oid rac std inline
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
const int N=50005;
int v[N],prime[N],mu[N],sum[N];
inline void get_mu(){
mu[1]=1;int m=0;
for(int i=2;i<=50000;i++){
if(!v[i]){
v[i]=i;
prime[++m]=i;
mu[i]=-1;
}
for(int j=1;j<=m;j++){
if(i*prime[j]>50000)break;
v[i*prime[j]]=prime[j];
if(i%prime[j]==0)break;
mu[i*prime[j]]=-mu[i];
}
}
for(int i=1;i<=50000;i++)sum[i]=sum[i-1]+mu[i];
}
int main(){
get_mu();
int n=read();
while(n--){
int a=read(),b=read(),c=read(),d=read(),k=read(),ans=0;
a--;c--;a/=k;b/=k;c/=k;d/=k;
if(b>d)swap(b,d),swap(a,c);
for(int l=1,r;l<=b;l=r+1){
r=min(b/(b/l),d/(d/l));
if(a/l)r=min(r,a/(a/l));
if(c/l)r=min(r,c/(c/l));
ans+=(b/l-a/l)*(d/l-c/l)*(sum[r]-sum[l-1]);
}
printf("%d\n",ans);
}
return 0;
}
标签:lin 函数 mat prim int oid rac std inline
原文地址:https://www.cnblogs.com/PPXppx/p/10848739.html