进阶数论artalter级服务第二弹:狄利克雷卷积和莫比乌斯反演
1.狄利克雷卷积
定义:对于两个数论函数\(f,g\),定义它们的卷积为h
\[h=f\times g =\sum_{d|n}f(d)g(\frac{n}{d})
\]
其中,\(\times\)是新运算“卷积”,而不是乘号。
应用:利用它,我们可以推式子(废话)和杜教筛
例如:
\[\sum_{d|n}\varphi(d)=\sum_{d|n}\varphi(d)*I(\frac{n}{d})=(\varphi\times I)(n)=n=id(n)
\]
所以
\[\varphi \times I=id
\]
2.莫比乌斯反演
\[\begin{aligned}
\text{莫比乌斯反演公式如下:}\\
&F(n)=\sum_{d|n}{f(d)}\\
\iff &f(n)=\sum_{d|n}{\mu(d)F(\frac{n}{d})}
\end{aligned}
\]
其中 \(\color{red}{\mu(d)}\)是莫比乌斯函数,它的定义如下:
\[\mu(d) =
\begin{cases}
1 &d=1\\
(-1)^{k} &d=p_1p_2p_3\cdots p_k \\
0 & \text{其他情况}
\end{cases}
\]
由定义可知,\(\mu(d)\)有一个\(\color{red}{\text{很重要}}\)的性质:
\[\sum_{d|n}{\mu(d)}=
\begin{cases}
1 &d=1\\
0 &d>1\\
\end{cases}
\]
用狄利克雷卷积可表示为:
\[\mu*I=\epsilon
\]
那么,我们就可以来证明一下莫比乌斯反演公式
\[\begin{aligned}
&\sum_{d|n}{\mu(d)F(\frac{n}{d})}\\
\iff &\sum_{d|n}{\mu(d)\sum_{k|{\frac{n}{d}}}f(k)}\\
\iff &\sum_{k|n}{f(k)\sum_{k|{\frac{n}{d}}}\mu(d)}\\
\iff &\sum_{k|n}{f(k)\sum_{d|{\frac{n}{k}}}\mu(d)}\\
\iff &\sum_{k|n}{f(k)[\frac{n}{k}=1]}\\
\iff &\sum_{k|n}{f(k)[n=k]}\\
\iff &f(n)
\end{aligned}
\]
但是,利用前面的狄利克雷卷积,我们可以方便的推出莫比乌斯反演:
\[F=\sum_{d|n}^nf(n)=I\times f
\]
\[F \times \mu=I\times f \times \mu = \epsilon \times f=f
\]
\[f=F \times \mu = \sum_{d|n}{\mu(d)F(\frac{n}{d})}
\]
3.欧拉反演
\[\sum_{d|n}(\frac{T}{d})\mu(d) =(\mu \times id)(n) =(\mu\times I \times \varphi)(n)=\varphi(n)
\]
4.莫比乌斯反演常见模板
1
\[\begin{aligned}
&\sum_i^n\sum_j^m[\gcd(i,j)=1]\\
\iff&\sum_i^n\sum_j^m\sum_{d|\gcd(i,j)}\mu(d)\\
\iff&\sum_{d=1}^n\mu(d)\sum_i^n\sum_j^m[d|\gcd(i,j)]\\
\iff&\sum_{d=1}^n\mu(d)\lfloor\frac{n}{d}\rfloor\lfloor\frac{m}{d}\rfloor\\
\end{aligned}
\]
现在式子可以用整数分块优化,具体参照 P2261余数求和
2
\[\begin{aligned}
&\sum_i^n\sum_j^m[\gcd(i,j)=k]\\
\iff&\sum_i^{\lfloor \frac{n}{k} \rfloor}\sum_j^{\lfloor \frac{m}{k} \rfloor}[\gcd(i,j)=1]\\
\iff&\cdots\\
\iff&\sum_{d=1}^n\mu(d)\lfloor\frac{n}{kd}\rfloor\lfloor\frac{m}{kd}\rfloor\\
\end{aligned}
\]
3.
\[\begin{aligned}
&\sum_i^n\sum_j^m{ij[\gcd(i,j)=k]}\\
\iff&k^2\sum_i^{\lfloor \frac{n}{k} \rfloor}\sum_j^{\lfloor \frac{m}{k} \rfloor}{ij {[\gcd(i,j)=1}] }\\
\iff&k^2\sum_i^{\lfloor \frac{n}{k} \rfloor}\sum_j^{\lfloor \frac{m}{k} \rfloor}{ij\sum_{d|\gcd(i,j)}\mu(d)}\\
\iff&k^2\sum_{d=1}^{\lfloor \frac{n}{k}\rfloor}{\mu(d)\sum_i^{\lfloor \frac{n}{k} \rfloor}\sum_j^{\lfloor \frac{m}{k} \rfloor}{ij[d|\gcd(i,j)]}}\\
\iff&k^2\sum_{d=1}^{\lfloor \frac{n}{k}\rfloor}{\mu(d)d^2\sum_i^{\lfloor \frac{n}{kd} \rfloor}i\sum_j^{\lfloor \frac{m}{kd} \rfloor}{j}}\\
设f(n) = \sum_{i=1}^ni,则f(n)=\frac{n(1+n)}{2}\\
\iff&k^2\sum_{d=1}^{\lfloor \frac{n}{k}\rfloor}{\mu(d)d^2f(\lfloor \frac{n}{kd} \rfloor)f(\lfloor \frac{m}{kd} \rfloor)}\\
\end{aligned}
\]
设T=kd
\[\begin{aligned}
\iff&\sum_{T=1}^n{f(\lfloor \frac{n}{T} \rfloor)f(\lfloor \frac{m}{T} \rfloor)} \sum_{d|n}{\mu(d)d^2(\frac{T}{d})^2} \\
\iff&\sum_{T=1}^n{f(\lfloor \frac{n}{T} \rfloor)f(\lfloor \frac{m}{T} \rfloor)} \sum_{d|n}{\mu(d)T^2 }\\
\end{aligned}
\]
\(\sum_{d|n}{\mu(d)T^2}\)可以用欧拉筛快速求出
4.
\[\begin{aligned}
&\sum_i^n\sum_j^mf(\gcd(i,j))\\
\iff&\sum_{T=1}^n{(\lfloor \frac{n}{T} \rfloor)(\lfloor \frac{m}{T} \rfloor)} \sum_{d|n}{\mu(d)f(\frac{T}{d}) }\\
\iff&\sum_{T=1}^n{(\lfloor \frac{n}{T} \rfloor)(\lfloor \frac{m}{T} \rfloor)} {(\mu\times f)(T)}\\
\end{aligned}
\]
\((\mu\times f)\)可以尝试用欧拉筛,杜教筛等方式求出前缀和