模板题……
[sumlimits_{i=1}^asumlimits_{j=1}^b[(i,j)=k] = sumlimits_{i=1}^asumlimits_{j=1}^b[k|i][k|j][({iover k},{jover k})=1]=sumlimits_{i=1}^{aover k}sumlimits_{j=1}^{bover k}[(i,j)=1]
]
继续化简
[sumlimits_{i=1}^{bover k}sumlimits_{j=1}^{dover k}sumlimits_{t|(i,j)}mu(t)=sumlimits_{i=1}^{bover k}[t|i]sumlimits_{j=1}^{dover k}[t|j]mu(t)=sumlimits_{t=1}^{max({bover k},{dover k})}{lfloor{{bover k}over t}
floor}{lfloor{{dover k}over t}
floor}mu(t)
]
然后上反演整除分块即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;
int pr[N*2],is[N*2],mu[N*2],cnt;
signed main() {
mu[0]=mu[1]=1; is[1]=1;
for(int i=2;i<N;i++) {
if(is[i]==0) {
pr[++cnt]=i;
mu[i]=-1;
}
for(int j=1; j<=cnt&&pr[j]*i<N; ++j) {
is[pr[j]*i]=1;
if(i%pr[j]==0) {
mu[pr[j]*i]=0;
break;
}
else {
mu[pr[j]*i]=-mu[i];
}
}
}
for(int i=1;i<N;i++) mu[i]+=mu[i-1];
int a,b,d;
cin>>a>>b>>d;
a/=d; b/=d;
int ans = 0;
int m=min(a,b);
int l=1,r;
while(l<=m) {
r=min(a/(a/l),b/(b/l));
ans+=(mu[r]-mu[l-1])*(a/l)*(b/l);
l=r+1;
}
cout<<ans<<endl;
}