Sieving Primes 2

Success! I found a reference to Mertens’ theorem in a paper by Adam Kalai, which is exactly what I needed to analyze the complexity of the prime sieve from the previous post.

Alas, my previous complexity guess was wrong. The actual complexity is O(n 3 /2 /log 3 n). Apparently my numerical estimates didn’t go out far enough (also I was biased towards finding O(nlog mn)).

From before, the cost of the algorithm is O(C(n)) where C(n)= c<nπ(lpf(c)) where c<n means all composite numbers up to n. Note that any number with lpf(c)=p can be written as pm, where m is not divisible by any prime smaller than p. By Mertens’ theorem, the density of numbers not divisible by primes less than p is q<p(1 1 q) e γlogp We can now estimate C(n) as C(n)= c<nπ(lpf(c)) = p<nπ(p) k=p n/p1 ifq<p,qk p<nπ(p)(npp) q<p(1 1 q) e γ p<nπ(p)(npp)1 logp e γ 2 nπ(x)(nxx)1 logxdxlogx e γ 2 nxlog 3 x(nxx) e γ 2 nnx 2 log 3 x Since the integrand is O(n/log 3 n) for x>n 1 /3 , we get C(n)=O(n 3 /2 /log 3 n). On the other hand, the integrand is ω(n/log 3 n) for x<n/4 , so in fact C(n)=Θ(n 3 /2 /log 3 n).

This adds another entry to the set of listful Sieve of Eratostheness-like algorithms that turn out to cost as much as trial division (up to a polylog factor). It’d be cool if a faster list based algorithm existed, but I expect that the answer is probably no.

Tags: , ,

Leave a Reply