定义:
定义 f , g f,g f,g两个积性函数的狄利克雷卷积运算(*)为: ( f ∗ g ) ( n ) = ∑ d ∣ n f ( d ) ∗ g ( n d ) (f*g)(n)=\sum_{d|n}f(d)*g(\frac{n}{d}) (f∗g)(n)=d∣n∑f(d)∗g(dn)
性质:
狄利克雷卷积满足:
- 交换律: f ∗ g = g ∗ f f*g=g*f f∗g=g∗f
- 结合律: ( f ∗ g ) ∗ h = f ∗ ( g ∗ h ) (f*g)*h=f*(g*h) (f∗g)∗h=f∗(g∗h)
- 分配律: f ∗ ( g + h ) = f ∗ h + g ∗ h f*(g+h)=f*h+g*h f∗(g+h)=f∗h+g∗h
- 单位元: f ∗ e = f f*e=f f∗e=f
常见函数卷积:
μ
∗
1
=
ϵ
μ∗1=ϵ
μ∗1=ϵ (莫比乌斯函数与1互为逆元)
ϕ
∗
1
=
I
d
ϕ∗1=Id
ϕ∗1=Id (欧拉函数与n互为逆元)
ϕ
=
I
d
∗
μ
ϕ=Id∗μ
ϕ=Id∗μ (莫比乌斯与欧拉的关系)
d
=
1
∗
1
d=1∗1
d=1∗1
1
=
μ
∗
d
1=μ∗d
1=μ∗d
杜教筛:
由于涉及内容太多,分成两篇博客进行讲述,建议先看前一篇,就当你已经看完前一篇了,我这里会讲的快一点
求 ∑ i = 1 n f ( i ) \sum_{i=1}^nf(i) ∑i=1nf(i),设为 A n s ( n ) Ans(n) Ans(n)
找一个积性函数g(x),那么 ∑ i = 1 n ( f ∗ g ) ( i ) = ∑ i = 1 n ∑ d ∣ i g ( d ) ∗ f ( i d ) \sum_{i=1}^{n}(f*g)(i)=\sum_{i=1}^{n}\sum_{d|i}g(d)*f(\frac{i}{d}) i=1∑n(f∗g)(i)=i=1∑nd∣i∑g(d)∗f(di)
显然: ∑ i = 1 n ∑ d ∣ i = ∑ d = 1 n ∑ d ∣ i i < = n \sum_{i=1}^{n}\sum_{d|i}=\sum_{d=1}^{n}\sum_{d|i}^{i<=n} i=1∑nd∣i∑=d=1∑nd∣i∑i<=n
那么: ∑ i = 1 n ( f ∗ g ) ( i ) = ∑ d = 1 n ∑ d ∣ i i < = n g ( d ) ∗ f ( n d ) = ∑ d = 1 n g ( d ) ∑ j = 1 [ n d ] f ( j ) \sum_{i=1}^{n}(f*g)(i)=\sum_{d=1}^{n}\sum_{d|i}^{i<=n}g(d)*f(\frac{n}{d})=\sum_{d=1}^{n}g(d)\sum_{j=1}^{[\frac{n}{d}]}f(j) i=1∑n(f∗g)(i)=d=1∑nd∣i∑i<=ng(d)∗f(dn)=d=1∑ng(d)j=1∑[dn]f(j)
接下来和前一篇一样: ∵ ∑ d = 1 n g ( d ) ∑ j = 1 [ n d ] f ( j ) = ∑ d = 2 n g ( d ) ∑ j = 1 [ n d ] f ( j ) + g ( 1 ) ∑ j = 1 n f ( j ) ∴ g ( 1 ) ∗ A n s ( n ) = ∑ i = 1 n ( f ∗ g ) ( i ) − ∑ d = 2 n g ( d ) A n s ( n / d ) \because\sum_{d=1}^{n}g(d)\sum_{j=1}^{[\frac{n}{d}]}f(j)=\sum_{d=2}^{n}g(d)\sum_{j=1}^{[\frac{n}{d}]}f(j)+g(1)\sum_{j=1}^{n}f(j)\\\therefore g(1)*Ans(n)=\sum_{i=1}^{n}(f*g)(i)-\sum_{d=2}^{n}g(d)Ans(n/d) ∵d=1∑ng(d)j=1∑[dn]f(j)=d=2∑ng(d)j=1∑[dn]f(j)+g(1)j=1∑nf(j)∴g(1)∗Ans(n)=i=1∑n(f∗g)(i)−d=2∑ng(d)Ans(n/d)
结论
A n s ( n ) = ∑ i = 1 n ( f ∗ g ) ( i ) − ∑ d = 2 n g ( d ) A n s ( n / d ) g ( 1 ) Ans(n)=\dfrac{\sum_{i=1}^{n}(f*g)(i)-\sum_{d=2}^{n}g(d)Ans(n/d)}{g(1)} Ans(n)=g(1)∑i=1n(f∗g)(i)−∑d=2ng(d)Ans(n/d)
按照上一篇的说法,递归+整除分块+线性筛 收尾。
例题:
求 ∑ i = 1 n ϕ ( i ) ∗ i \sum_{i=1}^n\phi(i)*i ∑i=1nϕ(i)∗i
显然,如果卷一个函数1的话,变成 ∑ i = 1 n ∑ d ∣ i ϕ ( d ) ∗ d \sum_{i=1}^n\sum_{d|i}\phi(d)*d ∑i=1n∑d∣iϕ(d)∗d,好像并没有什么简单的化简,而卷一个函数 I d Id Id的话,就变成了 ∑ i = 1 n ∑ d ∣ i ϕ ( d ) ∗ d ∗ i d → ∑ i = 1 n i ∑ d ∣ i ϕ ( d ) → ∑ i = 1 n i 2 \sum_{i=1}^n\sum_{d|i}\phi(d)*d*\frac{i}{d}\to\sum_{i=1}^ni\sum_{d|i}\phi(d)\to\sum_{i=1}^ni^2 i=1∑nd∣i∑ϕ(d)∗d∗di→i=1∑nid∣i∑ϕ(d)→i=1∑ni2而得到: 令 : f ( i ) = ϕ ( i ) ∗ i    ,    g ( i ) = i    ,    A n s ( n ) = ∑ i = 1 n ϕ ( i ) ∗ i 得 : A n s ( n ) = ∑ i = 1 n ( f ∗ g ) ( i ) − ∑ d = 2 n g ( d ) A n s ( n / d ) g ( 1 ) = ∑ i = 1 n i 2 − ∑ d = 2 n d ∗ A n s ( n / d ) 令:f(i)=\phi(i)*i\;,\;g(i)=i\;,\;Ans(n)=\sum_{i=1}^n\phi(i)*i\\得:Ans(n)=\dfrac{\sum_{i=1}^{n}(f*g)(i)-\sum_{d=2}^{n}g(d)Ans(n/d)}{g(1)}\\=\sum_{i=1}^{n}i^2-\sum_{d=2}^{n}d*Ans(n/d) 令:f(i)=ϕ(i)∗i,g(i)=i,Ans(n)=i=1∑nϕ(i)∗i得:Ans(n)=g(1)∑i=1n(f∗g)(i)−∑d=2ng(d)Ans(n/d)=i=1∑ni2−d=2∑nd∗Ans(n/d)这题就变得异常简单了
总结
当求积性函数前缀和不好求的时候,用狄利克雷卷上一个积性函数,使卷完后的式子的前缀和变得简单,卷完后的前缀和算出来基本上题目就完成了
- 如果出现 ϕ ( x ) \phi(x) ϕ(x),那么就凑 ∑ d ∣ n ϕ ( d ) = n \sum_{d|n}\phi(d)=n ∑d∣nϕ(d)=n
- 如果是 u ( x ) u(x) u(x),就凑 ∑ d ∣ n n ̸ = 1 u ( d ) = 0 \sum_{d|n}^{n\not=1}u(d)=0 ∑d∣nn̸=1u(d)=0
做题过程
- 想办法凑出 ∑ i = 1 n ∑ d ∣ i f ( d ) \sum_{i=1}^n\sum_{d|i}f(d) ∑i=1n∑d∣if(d),且要求这个式子可以直接求出来。
- 转化这个式子为 ∑ i = 1 n ∑ j = 1 ⌊ n i ⌋ f ( d ) \sum_{i=1}^n\sum_{j=1}^{\lfloor \frac{n}{i}\rfloor }f(d) ∑i=1n∑j=1⌊in⌋f(d),再拆出要求的答案: ∑ i = 1 n ∑ j = 1 ⌊ n i ⌋ f ( d ) = ∑ i = 2 n ∑ j = 1 ⌊ n i ⌋ f ( d ) + ∑ j = 1 n f ( d ) \sum_{i=1}^n\sum_{j=1}^{\lfloor \frac{n}{i}\rfloor }f(d)=\sum_{i=2}^n\sum_{j=1}^{\lfloor \frac{n}{i}\rfloor }f(d)+\sum_{j=1}^nf(d) ∑i=1n∑j=1⌊in⌋f(d)=∑i=2n∑j=1⌊in⌋f(d)+∑j=1nf(d)
- ∑ i = 2 n ∑ j = 1 ⌊ n i ⌋ f ( d ) \sum_{i=2}^n\sum_{j=1}^{\lfloor \frac{n}{i}\rfloor }f(d) ∑i=2n∑j=1⌊in⌋f(d)这部分往下递归做即可。
- 当 f ( i ) = ϕ ( i ) f(i)=\phi(i) f(i)=ϕ(i)或者 u ( i ) u(i) u(i)时, ∑ d ∣ n f ( i ) \sum_{d|n}f(i) ∑d∣nf(i)可以直接求出来,但是当 f ( i ) = i ∗ u ( i ) f(i)=i*u(i) f(i)=i∗u(i)时就不行了,得卷积一个 g ( i ) = i g(i)=i g(i)=i,此时 ∑ i = 1 n f ∗ g = ∑ i = 1 n ∑ d ∣ i f ( d ) g ( i d ) = ∑ i = 1 n ∑ d ∣ i u ( d ) = 1 \sum_{i=1}^nf*g=\sum_{i=1}^n\sum_{d|i}f(d)g(\frac{i}{d})=\sum_{i=1}^n\sum_{d|i}u(d)=1 ∑i=1nf∗g=∑i=1n∑d∣if(d)g(di)=∑i=1n∑d∣iu(d)=1。