"Summary" sieve

Gone on a fast league, to summarize sieve it.

 

For the time being only three, Egypt sieve, sieve lines, Du teach sieve.

 

How to say this thing. In fact, very flexible.

First, we know that most of sieve for sifting multiplicative function, and so great multiplicative function and prime relationship, we first talk about how prime number sieve it.

 

1. The prime number sieve

$ Fr. Root $ $ $ n-violence determination.

Comparable enumeration factor, if this is not the number of non-trivial factor (n-$ $ except $ 1, n $ factor), then this number is a prime number.

Complexity: $ O (\ {n} sqrt) $

 

$ Se. $ Angstrom sieves

Enumerate every number, to use it to screen out a multiple composite.

Complexity is: $ O (nlnln n) $

 

$ Th. $ Line screen

Each enumerator a prime number, or the number multiplied Hop screened out prime numbers together to ensure that a minimum number of prime factors to be screened out of engagement, so that each number is screened out once again to enumerate.

Complexity is: O (n)

 

Prime number sieve on these.

Then the screen dot product of a number of single function, usually the wire mesh.

 

In order to ensure the complexity of line screen, screen time to discuss three points situation.

The following are some examples:

Euler function

$$\varphi(n)=\sum\limits_{i=1}^{n}[i\perp n]$$

Consider the contribution of each quality factor.

Provided $ n = \ _ * p ^ c $

For each $ p ^ c $, the contribution of the answer is $ p ^ c \ frac {p-1} {p} $, and emotional understanding of what is actually quite similar to a "relatively prime density" of things, that is, each said interval $ p $ size, the distribution of prime numbers is uniform.

Euler function is a multiplicative function, then:

$$\varphi(n)=\prod\ p^c\frac{p-1}{p}=n\prod\frac{p-1}{p}$$

Let's line sieve it.

$ Fr.i \ \ p 那么 $ $ \ varphi (i) = i-1 $

$ Se.i% p_j! = 0 $ then a function of the nature of the product, $ \ varphi (ip_j) = \ varphi (i) \ varphi (p_j) $

$ Th.i% p_j == 0 $ substituting according to the formula, the newly discovered equation only prime number n-$ $ foremost contribute, while $ \ $ Prod later portion has been calculated.

Then: $ \ varphi (ip_j) = \ varphi (i) p_j $

 

2. The number of divisor

Provided $ n = \ _ * p ^ c $

By definition, each quality factor index enumerated in the divisor obtained:

$d(n)=\prod c+1$

It may be found to be multiplicative function.

Let's line sieve it.

首先加入一个辅助数组$a(i)$表示$i$最小的质因子在$i$中的指数。

$fr.i\in\ p$那么$d(i)=2,a(i)=1$

$se.i%p_j!=0$根据积性函数的性质,$d(ip_j)=d(i)d(p_j),a(ip_j)=1$

$th.i%p_j==0$根据公式代入,$d(ip_j)=d(i)\frac{(a(i)+1)}{(a(i)+2)},a(ip_j)=a(i)+1$

 

3.自然数幂函数

$$f_d(i)=i^d$$

这是完全积性函数。

其实要简单很多了就。

还是套用线筛的模板,然后每乘入一个质数的时候。

$$f_d(ip_j)=f_d(i)p_j^d$$

每次筛出质数的时候用快速幂求出$p_j^d$,复杂度是$O(n\frac{log_2(n)}{ln(n)})$的,仍然是线性。

 

4.莫比乌斯函数

$$\mu(n)=\begin{cases} (-1)^w &\ n=\prod\limits_{i=1}^{w}p_i&\\0 &\ n=p^2\prod\limits_{i=1}^{w}p_i^{c_i}&\end{cases}$$

它是积性函数

我们来线筛它。

$fr.i\in\ p$那么$\mu(i)=-1$

$se.i%p_j!=0$那么$\mu(ip_j)=\mu(i)\mu(p_j)$

$th.i%p_j==0$那么$\mu(ip_j)=0$

 

5.约数和函数

根据定义,枚举每个质因子在约数中出现的指数。

设$n=\_*p^c$

$$\sigma(n)=\prod\sum\limits_{i=0}^{c}p^i$$

发现是等比数列可以直接求和。

$$\sigma(n)=\prod\frac{1-p^c}{1-p}$$

那么我们需要维护一个函数$b(n)$代表$n$最小的质因子的最大指数次幂,也就是说对于$n$的最小质因子$p$,$b(n)=\sum\limits_{i=0}^{c}p^i$,同时需要借用上面筛过的函数$f_d(n)$和$a(n)$。

我们来线筛它。

$fr.i\in\ p$那么$b(i)=i+1,\sigma(i)=i+1$

$se.i%p_j!=0$那么$b(ip_j)=p_j+1,\sigma(ip_j)=\sigma(i)\sigma(p_j)$

$th.i%p_j==0$那么$b(ip_j)=b(i)+f_{a(ip_j)}{p_j},\sigma(ip_j)=\sigma(i)\frac{b(i)}{b(ip_j)}$

 

6.最大共因数

也就是在$k$一定的情况下求:

$gcd(n,k)=\prod\limits_{p}p^{min(c_n,c_k)}$

可以发现是积性函数。

仍然利用函数$a(n)$,设函数$g_n(p)$为$n$中质因子$p$的最大幂指数。

我们来线筛它。

$fr.i\in\ p$那么$gcd(i,k)=i[i|n]+[i\perp n]$

$se.i%p_j!=0$那么$gcd(ip_j,k)=gcd(i,k)gcd(p_j,k)$

$th.i%p_j==0$那么$gcd(ip_j,k)=gcd(i,k)(p_j[a(i)<g_n(p_j)]+[a(i)>g_n(p_j)])$

 

线筛复杂度已经很优秀了,可是就是有毒瘤出题人出数据出到$1e12$,这时候杜教筛就出场了。

杜教筛用来筛特定积性函数的前缀和。

设目标函数为$f$,其前缀和为$S$

$*$为狄利克雷卷积,相关证明在约数容斥有所交待。

首先设函数:

$$h=g*f$$

那么:

$$\begin{array}{rcl}\\ \sum\limits_{i=1}^{n}h(i)&=&\sum\limits_{i=1}^{n}\sum\limits_{d|i}g(d)f(\frac{i}{d})\\&=&\sum\limits_{d=1}^{n}g(d)\sum\limits_{i=1}^{\frac{n}{d}}f(i)\\&=&\sum\limits_{d=1}^{n}g(d)S(\frac{n}{d})\end{array}$$

移项得到:

$$S(n)=\sum\limits_{i=1}^{n}h(i)-\sum\limits_{d=2}^{n}g(d)S(\frac{n}{d})$$

这样的话如果我们的$h$和$g$的前缀和很好求,后面的部分就可以用数论分块来解决了。

 

Guess you like

Origin www.cnblogs.com/Lrefrain/p/11791013.html