题目大意:
给定(n,m,k,) 求
[sumlimits_{x=1}^nsumlimits_{y=1}^m[gcd(x,y)==k]
]
莫比乌斯反演入门题,先进行一步转化,将每个(x,y)除以(k),则答案变为
[sumlimits_{x=1}^{lfloorfrac{n}{k}
floor} sumlimits_{y=1}^{lfloorfrac{m}{k}
floor} [gcd(x,y)==1]
]
发现最右边的条件可以莫比乌斯反演
[sumlimits_{x=1}^{lfloorfrac{n}{k}
floor} sumlimits_{y=1}^{lfloorfrac{m}{k}
floor} sumlimits_{d|n}mu(d)
]
我们将枚举因子提到前面,改成枚举约数
[sumlimits_{d=1}^{min(frac{n}{k},frac{m}{k})}mu(d) sumlimits_{x=1}^{lfloorfrac{n}{k}
floor} sumlimits_{y=1}^{lfloorfrac{m}{k}
floor}
]
易证:(1-n)中k个倍数个数为(lfloorfrac{n}{k}
floor)$
所以原式等价于
[sumlimits_{d=1}^{min(frac{n}{k},frac{m}{k})}mu(d)lfloorfrac{n}{kd}
floor lfloorfrac{m}{kd}
floor
]
用除法分块可以做到(O(sqrt{n}))