# 题意

$T\le 5\times 10^4$ 次询问，每次询问 $a,b,c,d,k\le 5\times 10^4$，求

$\sum _{i=a}^b\sum _{j=c}^d[gcd(i,j)=k]$

# 分析

$\sum _{i=1}^n\sum _{j=1}^m[gcd(i,j)=1]$

\begin{aligned} \sum _{i=1}^n\sum _{j=1}^m[gcd(i,j)=k]&=\sum _{i=1}^n\sum _{j=1}^m\sum _{k|i,k|j}\sum _{d|\frac{i}{k},d|\frac{j}{k}}\mu(d) \\ &=\sum _{d=1}^n\sum _{i=1}^{\lfloor\frac{n}{k}\rfloor}\sum _{j=1}^{\lfloor\frac{m}{k}\rfloor}\mu (d) \\ &=\sum _{d=1}^n\mu (d) \lfloor\frac{\lfloor\frac{n}{k}\rfloor}{d}\rfloor \lfloor\frac{\lfloor\frac{m}{k}\rfloor}{d}\rfloor \end{aligned}

# 代码

#include<bits/stdc++.h>
using namespace std;
int x=0,f=1;
char c=getchar_unlocked();
for (;!isdigit(c);c=getchar_unlocked()) if (c=='-') f=-1;
for (;isdigit(c);c=getchar_unlocked()) x=x*10+c-'0';
return x*f;
}
typedef long long giant;
const int maxn=5e4+1;
bool np[maxn];
int p[maxn],mu[maxn],ps=0;
giant calc(int n,int m) {
giant ret=0;
if (n>m) swap(n,m);
for (int i=1,j;i<=n;i=j+1) {
j=min(n/(n/i),m/(m/i));
ret+=(giant)(mu[j]-mu[i-1])*(n/i)*(m/i);
}
return ret;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif
mu[1]=1;
for (int i=2;i<maxn;++i) {
if (!np[i]) p[++ps]=i,mu[i]=-1;
for (int j=1;j<=ps && i*p[j]<maxn;++j) {
np[i*p[j]]=true;
if (i%p[j]==0) break;
mu[i*p[j]]=-mu[i];
}
}
for (int i=2;i<maxn;++i) mu[i]+=mu[i-1];