传送门
最后把式子化成这个样子
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=5e4;
int prime[N+5],mu[N+5],p[N+5];
int T,a,b,k,ans;
inline void get_mu(){
mu[1]=1;
for (int i=2;i<=N;++i){
if (!p[i]){
prime[++prime[0]]=i;
mu[i]=-1;
}
for (int j=1;j<=prime[0]&&i*prime[j]<=N;++j){
p[i*prime[j]]=1;
if (i%prime[j]==0){
mu[i*prime[j]]=0;
break;
}
else mu[i*prime[j]]=-mu[i];
}
}
}
int main(){
get_mu();
for (int i=1;i<=N;++i) mu[i]+=mu[i-1];
scanf("%d",&T);
while (T--){
scanf("%d%d%d",&a,&b,&k);
a/=k; b/=k;
if (a>b) swap(a,b);
ans=0;
for (int i=1,j;i<=a;i=j+1){
j=min(a/(a/i),b/(b/i));
ans+=(a/i)*(b/i)*(mu[j]-mu[i-1]);
}
printf("%d\n",ans);
}
}