10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3.2 Sieving 127<br />

}<br />

S = S \ (pS ∩ [1,N]); // Now S = Sl.<br />

l = l +1;<br />

6. [Return the set of primes in [1,N]]<br />

return (S \{1}) ∪{p1,p2,...,pm};<br />

Each set Sl consists of the numbers in [1,N] that are coprime to p1,p2,...,pl.<br />

Thus the first member after 1 is the (l + 1)-th prime, pl+1. Let us count<br />

the number of operations in Algorithm 3.2.2. The number of operations for<br />

Step [Setup] is O((N/ ln N) <br />

i≤k 1/pi) = O(N ln ln N/ ln N). (In fact, the<br />

expression ln ln N may be replaced with ln ln ln N, but it is not necessary for<br />

the argument.) For Step [Roll wheel], the number of operations is #Sk ≤<br />

⌈N/Mk⌉ϕ(Mk) =O(Nϕ(Mk)/Mk), where ϕ is Euler’s function. The fraction<br />

ϕ(Mk)/Mk is exactly equal to the product of the numbers 1 − 1/pi for<br />

i =1uptok. By the Mertens Theorem 1.4.2, this product is asymptotically<br />

e−γ / ln pk. Further, from the prime number theorem, we have that pk is<br />

asymptotically equal to ln N. Thus the number of operations for Step [Roll<br />

wheel] is O(N/ ln ln N).<br />

It remains to count the number of operations for steps [Find gaps] and<br />

[Find special set]. Suppose S = Sl−1, andletGl = G. The number of members<br />

of S ∩ [1,N/pl] isO(N/(pl ln pl−1)), by Mertens. Thus, the total number of<br />

steps to find all sets Gl is bounded by a constant times<br />

m<br />

l=k+1<br />

N/(pl ln pl−1) =O(N/ ln pk) =O(N/ ln ln N).<br />

The number of additions required to compute gpl for g in Gl by the repeated<br />

doubling method is O(ln g) =O(ln N). The sum of all of the values of g in Gl<br />

N/pl <br />

is at most N/pl, so that the number of members of Gl is O .Thus<br />

the total number of additions in Step [Find gaps] is bounded by a constant<br />

times<br />

m<br />

l=k+1<br />

<br />

N<br />

pl<br />

ln N ≤<br />

⌊ √ N⌋<br />

<br />

i=2<br />

N<br />

i<br />

ln N ≤<br />

√ N<br />

1<br />

N<br />

t ln Ndt=2N 3/4 ln N.<br />

We cannot be so crude in our estimation of the number of operations in Step<br />

[Find special set]. Each of these operations is the simple bookkeeping step<br />

of deleting a member of a set. Since no entry is deleted more than once, it<br />

suffices to count the total number of deletions in all iterations of Step [Find<br />

special set]. But this total number of deletions is just the size of the set Sk<br />

√N,N lessthenumberofprimesin . This is bounded by #Sk, whichwe<br />

have already estimated to be O(N/ ln ln N).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!