# BZOJ2301 Problemb

f(i)=x=1ny=1m[gcd(x,y)=i]

F(i)=x=1ny=1m[i|gcd(x,y)]=[ni][mi]
f(i)=i|dμ(di)F(d)

# include <algorithm>
# include <cstdio>
using namespace std;
const int maxn = 50010;
const int maxs = 50000;
int mu[maxn]={0,1};
bool nprime[maxn];
int prime[maxn],num;
int pre[maxn];
int k;
void getprime(){
for (int i=2;i<=maxs;++i){
if (!nprime[i]){ prime[num++]=i; mu[i]=-1; }
for (int j=0;j<num&&prime[j]*i<=maxs;++j){
nprime[i*prime[j]] = true;
if (i%prime[j] == 0){
mu[i*prime[j]] = 0;
break;
}
else mu[i*prime[j]] = -mu[i];
}
}
}

int getnum(int x,int y){
int last = 0;
int ans = 0;
x /= k; y /= k;
for (int i=1;i<=min(x,y);i=last+1){
last = min(x/(x/i),y/(y/i));
ans += (pre[last]-pre[i-1])*(x/i)*(y/i);
}
return ans;
}

int main(){
getprime();
for (int i=1;i<=maxs;++i) pre[i] = pre[i-1] + mu[i];
int T; scanf("%d",&T);
while (T--){
int a,b,c,d;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
--a; --c;   //Preffix
printf("%d\n",getnum(b,d)-getnum(a,d)-getnum(c,b)+getnum(a,c));
}
return 0;
}


©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客