莫比乌斯反演笔记

经典问题(以下全部默认$n\leqslant m$):
$\sum\limits_{i=1}^n\sum\limits_{j=1}^{m}gcd(i,j)=\sum_{d=1}^n\varphi(d)\lfloor\frac{n}{d}\rfloor\lfloor\frac{m}{d}\rfloor$
$O(n)-O(\sqrt{n})$求解。

$\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}[gcd(i,j)=p]=\sum\limits_{d=1}^{\lfloor\frac{n}{p}\rfloor}\mu(d)\lfloor\frac{n}{pd}\rfloor\lfloor\frac{m}{pd}\rfloor$
$O(n)-O(\sqrt{n})$求解。


$\begin{align*}
\sum_{i=1}^{n}\sum_{j=1}^{m}lcm(i,j)&=\sum_{i=1}^n\sum_{j=1}^{m}\frac{ij}{gcd(i,j)}
\\ &=\sum_{d=1}^n\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)=d]\frac{ij}{d}
\\ &=\sum_{d=1}^n\sum_{i=1}^{\lfloor \frac{n}{d} \rfloor}\sum_{j=1}^{\lfloor \frac{m}{d} \rfloor}[i\perp j]ijd
\\ &=\sum_{d=1}^{n}d\sum_{i=1}^{\lfloor \frac{n}{d} \rfloor}\sum_{j=1}^{\lfloor \frac{m}{d} \rfloor}ij\sum_{p|i,p|j}\mu(p)
\\ &=\sum_{d=1}^{n}d\sum_{p=1}^{\lfloor \frac{n}{d} \rfloor}\mu(p)p^2S(\lfloor\frac{n}{pd}\rfloor)S(\lfloor\frac{m}{pd}\rfloor)
\\ &=\sum_{T=1}^{n}S(\lfloor\frac{n}{T}\rfloor)S(\lfloor\frac{m}{T}\rfloor)T\sum_{p|T}\mu(p)p^2
\end{align*}$
考虑线性筛出$f(n)=\sum_{d|n}\mu(d)\cdot d$
$p\mid i$时,$f(pi)=f(i)$,当$p\nmid i$时,$f(pi)=(1-p)f(i)$
$O(n)-O(\sqrt{n})$求解。

$f(n)=\sum\limits_{i=1}^{n}[i\perp n]i,f(1)=1,f(n)=\frac{\varphi(n)\cdot n}{2}$

$\sigma_0(i,j)=\sum\limits_{x|i}\sum\limits_{y|j}[x\perp y]$

 

$\sigma_0(n),\sigma_1(n)$线性筛可以做到$O(n)-O(1)$,单次询问可以做到$O(\sqrt{n})$。


$\Sigma_0(n),\Sigma_1(n)$单次询问可以做到$O(\sqrt{n})$

posted @ 2019-04-28 17:43  HocRiser  阅读(180)  评论(0编辑  收藏  举报