浅谈PN筛

· · 算法·理论

0x00 本文约定

  1. 本文不区分素数、质数。

0X01 PN筛简介

PN (Powerful-Number) 筛,是解决一些积性函数 f 的求和在 \sqrt{n}\ln n 左右的复杂度。\ 特征:

::::info[证明]{open} 由 Dirichlet 卷积定义得 ,f(p)=g(p)h(1)+h(p)g(1) .\ 其中 g 、 p 为积性函数,所以g(1)=h(1)=1 。\ 联立上式得 h(p)=f(p)-g(p)=0 。

\square

::::

\forall x\ isn't\ \text{PN}\ ,\ h(x)=0

::::info[证明]{open} 因为 x 不是 PN,所以必定有一个 p_i 使得 c_i=1 。\ 因为 h 为积性函数, h(x)=h(\dfrac{n}{p_i})h(p_i)=0。

\square

::::

\begin{aligned} \sum_{i=1}^n f(i)\\ =\sum_{i=1}^n\sum_{d=1}^n[d|i]h(d)g(\dfrac{i}{d})\\ =\sum_{d=1}^nh(d)\sum_{i=1}^n[d|i]g(\dfrac{i}{d})\\ \text{不妨令 $i'=\dfrac{i}{d}$ 。}\\ \sum_{d=1}^nh(d)\sum_{i'=1}^{\lfloor\dfrac{n}{d}\rfloor}g(i')\\ =\sum_{d=1}^nh(d)G(\lfloor\dfrac{n}{d}\rfloor)\\ =\sum_{d=1\ d\ is\ \text{PN}}^n h(d)G(\lfloor\dfrac{n}{d}\rfloor) \end{aligned}

任务变为如何求PN的 h 值。

0x04 h(x) , 其中 x 是PN

由于 h 是积性函数,即求h(p^c) 。 如法炮制:

=\sum_{i=1}^cg(p^i)h(p^{c-i})+h(p^c)

复杂度 O(c^2) 。 可以预处理出小于 \sqrt{n} 的素数的次幂的 h 值。\ 最终复杂度: O(\sum_{i=1}^{\sqrt{n}}[i\in \mathbb{P}]\log_i^2n) 。

0x05 复杂度证明

由 素数定理得 : [x\in\mathbb{P}]= \pi(x)-\pi(x-1)\approx \dfrac{1}{x\ln x}-\dfrac{1}{x\ln x-\ln x}\approx \dfrac{1}{\ln x} \ 此处只是期望\ 原式为

\sum_{i=1}^{\sqrt{n}}\dfrac{\ln^2n}{\ln^3 i}\\ \approx\ln^2n\int_2^{\sqrt{n}}\dfrac{1}{ln^3i}\\ = O\left(\ln^2 n\dfrac{\sqrt{n}}{\ln n}\right)\\ = O\left(\sqrt{n}\ln n\right)

总复杂度为 O\left(\sqrt{n}\ln n+T\int_0^nx^{-\frac{1}{2}}f(x)dx\right) 。\ 其中 O(f(x)) 为 计算 G(x) 的复杂度。

0x06 更多

当 g 是完全积性函数时

有

\\=f(p^c) - g(p)\sum_{i=0}^{c-1}g(p^i)h(p^{(c-1)-i})\\ =f(p^c)-g(p)f(p^{c-1})

0x07 习题

【模板】Min_25筛
用杜教筛解决 $G(n)$ 即可。 ##### [例题2](https://www.luogu.com.cn/problem/U634898) 注意原式为 $\sum_{i=1}^n((\mu^2\varphi)*1)(i)$。 ##### [例题3](https://www.luogu.com.cn/problem/U600444) 注意原式为 $\sum_{i=1}^n\sum_{d|i}\mu^2(d)$。