Sieve of Eratosthenes
Algorithm
Mark all multiples of each prime p≤√n as composite. Remaining unmarked numbers are prime.
Examples
Example 1. Primes up to 20.
Solution. 2,3,5,7,11,13,17,19.
In Depth
The Sieve of Eratosthenes finds all primes up to \(N\) by iteratively marking multiples of each prime as composite. Start with all integers from 2 to \(N\); mark multiples of 2, then 3, then 5, and so on up to \(\sqrt{N}\). Unmarked numbers are prime.
Time complexity: \(O(N\log\log N)\) — nearly linear. Space: \(O(N)\). The segmented sieve reduces space to \(O(\sqrt{N})\) by processing the range in blocks, enabling sieving of very large ranges. The linear sieve achieves \(O(N)\) time by ensuring each composite is crossed off exactly once.
The prime counting function \(\pi(N)\) (number of primes \(\leq N\)) is computed exactly by the sieve. The prime number theorem gives the asymptotic \(\pi(N)\sim N/\ln N\). More precise estimates use the logarithmic integral \(\text{Li}(N)=\int_2^N dt/\ln t\).
Generalizations: the Sieve of Sundaram finds odd primes; the Sieve of Atkin is faster in practice for large \(N\). Analytic sieves (Brun, Selberg, large sieve) are theoretical tools that estimate the count of primes in arithmetic progressions and twin prime pairs.
The sieve principle extends beyond primes: inclusion-exclusion sieves count integers in a range satisfying various divisibility conditions. Brun's theorem (proved using his sieve) shows the sum of reciprocals of twin primes converges, unlike the divergent sum of prime reciprocals.
Key Properties & Applications
The sieve of Eratosthenes has time complexity \(O(N\log\log N)\) due to the harmonic series of prime reciprocals: \(\sum_{p\leq N}1/p\sim\ln\ln N\). The segmented sieve processes the range \([L,R]\) using only primes up to \(\sqrt{R}\), requiring \(O(\sqrt{R})\) space.
Wheel factorization pre-eliminates multiples of small primes (2, 3, 5, …) before sieving, reducing the work by a constant factor. A wheel of circumference 30 (= 2×3×5) reduces candidates by 73%, giving a practical speedup.
The prime number theorem implies the average gap between consecutive primes near \(N\) is \(\ln N\). Cramér's conjecture predicts the maximum gap is \(O((\ln N)^2)\). The largest known prime gaps are consistent with this but the conjecture is unproved.
Further Reading & Context
The study of sieve of eratosthenes connects to many areas of mathematics and its applications. Understanding the foundational definitions and theorems provides the basis for advanced work in analysis, algebra, and applied mathematics.
Historical development: most mathematical concepts evolved over centuries, with contributions from mathematicians across many cultures. The modern axiomatic treatment provides rigor, while computational tools enable practical application.
In modern mathematics, this topic appears in graduate courses and research across pure and applied mathematics. Connections to computer science, physics, and engineering make it a versatile and important area of study. Mastery of the core results and techniques opens doors to research in number theory, analysis, geometry, and beyond.
Recommended next steps: work through the standard theorems with full proofs, explore the connections to related topics listed above, and practice with a variety of problems ranging from computational exercises to theoretical proofs. The interplay between different areas of mathematics is one of the subject's greatest rewards.