莫比乌斯反演

莫比乌斯函数

\(\mu(n)= \begin{cases} 1&n=1\\ 0&n\text{ 含有平方因子}\\ (-1)^k&k\text{ 为 }n\text{ 的本质不同质因子个数}\\ \end{cases}\)

莫比乌斯反演

如果\(F(n)\)\(f(n)\)是两个数论函数,并且满足条件:

\(\displaystyle F(n)=\sum_{d|n}f(d)\)

那么存在一个结论:

\(\displaystyle f(n)=\sum_{d|n}\mu(d)F(\lfloor\frac{n}{d}\rfloor)\)

  • 证明一:

\(\displaystyle\sum_{d|n}\mu(d)F(\lfloor\frac{n}{d}\rfloor)=\sum_{d|n}\mu(d)\sum_{i|\lfloor\frac{n}{d}\rfloor}f(i)\)

\(\displaystyle =\sum_{i|n}f(i)\sum_{d|\lfloor\frac{n}{i}\rfloor}\mu(d)=f(n)\)

  • 证明二

首先引入

狄利克雷卷积

  • 定义

函数\(f,g\)为数论函数

狄利克雷卷积可以表示为\(f∗g\)

\(h=f∗g\)

\(\displaystyle h(n)=\sum_{d|n}f(d)g(\dfrac{n}{d})\)

狄利克雷卷积满足分配率,结合律,交换律

  • 一些柿子

\(\sum_{d|n}\varphi(d)=\sum_{d|n}\varphi(d)*I(\frac{n}{d})=(\varphi * I)(n)=n=id(n)\)

也就是\(\varphi * I=id\)

其中\(I(n)=1 \;\;\; id(n)=n\)

  • 单位元:

\(\varepsilon\)\(Dirichlet\)卷积运算中的单位元,即对于任何数论函数 \(f\),都有\(f * \varepsilon = f\)

\(\varepsilon(n)=[n==1]\)

  • 欧拉反演

\(\displaystyle \varphi(n)=(\mu* I * \varphi)(n)=(\mu * id)(n)=\sum_{d|n}(\frac{T}{d})\mu(d)\)

关于狄利克雷的更多性质可以参考oi-wiki

扯偏了

回到证明

\(\displaystyle F=\sum_{d|n}^nf(n)=I* f\)

$F * \mu=I*f *\mu = \epsilon * f=f $

\(f=F * \mu = \sum_{d|n}{\mu(d)F(\frac{n}{d})}\)

其实通过做题可以发现,以上基本是废话

最常用的性质\(\displaystyle [gcd(i,j)==1] <=> \sum_{d∣gcd(i,j)}​μ(d)\)

基本上记住它就行了。

感谢\(artalter\)大佬的讲解

例题

A. YY的GCD

首先是莫反套路

\(\displaystyle \sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)\in prime]\)

\(\displaystyle =\sum_{p\in prime}^{n}\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)== p]\)

\(\displaystyle =\sum_{p\in prime}^{n}\sum_{i=1}^{\lfloor\frac{n}{p}\rfloor}=\sum_{j=1}^{\lfloor\frac{m}{p}\rfloor}[gcd(i,j)== 1]\)

\(\displaystyle =\sum_{p\in prime}^{n}\sum_{i=1}^{\lfloor\frac{n}{p}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{p}\rfloor}\sum_{d|gcd(i,j)}\mu(d)\)

\(\displaystyle =\sum_{p\in prime}^{n}\sum_{d=1}^{\lfloor\frac{n}{p}\rfloor}\mu(d){\lfloor\frac{n}{dp}\rfloor}{\lfloor\frac{m}{dp}\rfloor}\)

然后是数论分块套路

\(T=dp\)

\(\displaystyle =\sum_{p\in prime}^{n}\sum_{d=1}^{\lfloor\frac{n}{p}\rfloor}\mu(d){\lfloor\frac{n}{T}\rfloor}{\lfloor\frac{m}{T}\rfloor}\)

\(\displaystyle =\sum_{T=1}^{n}{\lfloor\frac{n}{T}\rfloor}{\lfloor\frac{m}{T}\rfloor}\sum_{p\in prime\;p|T}\mu(\lfloor\frac{T}{p}\rfloor)\)

后面的预处理,前面数论分块

B. 数表

求约数和都忘了。。。oi-wiki

\(\displaystyle f[n]=\sum_{d|n}^{n}d\)

不难发现是求

\(\displaystyle \sum_{i=1}^{n}\sum_{j=1}^{m}f[gcd(i,j)](f[gcd(i,j)]<=A)\)

\(\displaystyle =\sum_{d=1}^{n}f[d]\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{d}\rfloor}[gcd(i,j)==1](f[d]<=A)\)

\(\displaystyle =\sum_{d=1}^{n}f[d]\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{d}\rfloor}\sum_{x|gcd(i,j)}\mu(x)(f[d]<=A)\)

\(\displaystyle =\sum_{d=1}^{n}f[d]\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{d}\rfloor}\sum_{x|gcd(i,j)}\mu(x)(f[d]<=A)\)

\(\displaystyle =\sum_{d=1}^{n}f[d]{\lfloor\frac{n}{dx}\rfloor}{\lfloor\frac{m}{dx}\rfloor}\sum_{x=1}^{\lfloor\frac{n}{d}\rfloor}\mu(x)(f[d]<=A)\)

\(T=dx\)

\(\displaystyle =\sum_{T=1}^{n}{\lfloor\frac{n}{T}\rfloor}{\lfloor\frac{m}{T}\rfloor}\sum_{d|T}f[d]\mu({\lfloor\frac{n}{d}\rfloor})(f[d]<=A)\)

前面显然数论分块,询问离线后按照\(a\)排个序,\(f[d]\)排序后,按需求\(a\),加入树状数组动态维护

我菜的连\(f[d]\)怎么求都忘了...

赶进度,后面的咕咕咕

posted @ 2022-06-08 15:16  Chen_jr  阅读(62)  评论(1编辑  收藏  举报