暑期的学习开始了,今天先来讲一下杜教筛吧(反演的坑以后再填。。。
核心公式:
我们设(egin{aligned}S(n)=sum_{i=1}^{n}(f * g)_ {(i)}end{aligned}),且(g)为一个完全积性函数。
那么可以得到:
(egin{aligned}sum_{i=1}^n((f* 1)_ {(i)} imes g)=sum_{i=1}^ng(i) imes S(lfloorfrac n i floor)end{aligned})
证明:
(egin{aligned}sum_{i=1}^n((f* 1)_ {i} imes g)&=sum_{i=1}^ng(i) imessum_{d|i}f(d)\&=sum_{d=1}^nsum_{i=1}^{lfloorfrac n d floor}g(id) imes f(d)\&=sum_{d=1}^ng(i) imes g(d) imes f(d)\&=sum_{d=1}^ng(d) imes S(lfloorfrac n d floor)end{aligned})
证毕
具体实现:
-
(mu)函数求前缀和:
根据(mu* 1=epsilon),将(epsilon)作为(S)、(mu)作为(f)、(1)作为(g)代入上述公式,得到:(egin{aligned}sum_{i=1}^nepsilon(i)=sum_{d=1}^n1(d) imes S(lfloorfrac n d floor)end{aligned})
把(d=1)拿出来,再化简得:(egin{aligned}1=S(n)+sum_{d=2}^nS(lfloorfrac n d floor)end{aligned})
移个项,得:(egin{aligned}S(n)=1-sum_{d=2}^nS(lfloorfrac n d floor)end{aligned})
-
(varphi)函数求前缀和:
根据(varphi* 1=id)得到:
(egin{aligned}S(n)=frac{n imes(n+1)}{2}+sum_{d=2}^nS(lfloorfrac n d floor)end{aligned})