mcfx's blog - 莫比乌斯反演
/category/mob/
-
BZOJ 2694 & 4659 Lcm
/archives/181/
2017-02-28T00:16:00+08:00
###Description
![fa(1).jpg][1]
###Solution
$$\sum_i^n\sum_j^m[\mu(gcd(i,j))\neq 0]lcm(i,j)$$
$$=\sum_k^n|\mu(k)|\sum_i^{\frac{n}{k}}\sum_j^{\frac{n}{k}}[gcd(i,j)=1]i\cdot j\cdot k$$
$$=\sum_k^n|\mu(k)|\cdot k\sum_d^{\frac{n}{k}}\mu(d)\cdot d^2\sum_i^{\frac{n}{k\cdot d}}\sum_j^{\frac{m}{k\cdot d}}i\cdot j$$
$$=\sum_k^n\sum_d[d|k]\mu(d)\cdot d^2\cdot|\mu(\frac{k}{d})|\cdot\frac{p}{d}\cdot\frac{\frac{n}{k}\cdot(\frac{n}{k}+1)}{2}\cdot\frac{\frac{m}{k}\cdot(\frac{m}{k}+1)}{2}$$
最后的式子,前面是积性函数,后面根号分块
###Code
```c++
#define _GLIBCXX_IOSTREAM
#include
#define N 4000001
int pri[N],pm,f[N],ps[N],pc[N];
bool np[N];
int main()
{
for(int i=2;i