分析
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int N = 50000;
int mu[N+10],p[N+10];
bool is[N+10];
inline void go(){
int i,j,k,cnt=0;
mu[1]=1;
for(i=2;i<=N;i++){
if(!is[i])p[++cnt]=i,mu[i]=-1;
for(j=1;j<=cnt,p[j]*i<=N;j++){
is[p[j]*i]=1;
if(i%p[j]==0){
mu[i*p[j]]=0;
break;
}
mu[i*p[j]]=-mu[i];
}
}
for(i=2;i<=N;i++)mu[i]+=mu[i-1];
}
inline int f(int n,int m,int k){
int le=1,ri,res=0;
n/=k,m/=k;
for(;le<=min(n,m);le=ri+1){
ri=min(n/(n/le),m/(m/le));
res+=(mu[ri]-mu[le-1])*(n/le)*(m/le);
}
return res;
}
int main(){
int t,a,b,c,d,k;
go();
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d%d",&a,&c,&b,&d,&k);
a--,b--;
printf("%d
",f(c,d,k)-f(a,d,k)-f(c,b,k)+f(a,b,k));
}
return 0;
}