TOPICS
Search

Sieve of Eratosthenes


EratosthenesSieve

The sieve of Eratosthenes is an algorithm for making tables of primes. Sequentially write down the integers from 2 to an integer n>=2. Starting with 2, take the remaining primes p<=sqrt(n) in increasing order and cross out all multiples of p greater than p. For example, when sieving up to 50, first cross out all numbers greater than 2 that are divisible by 2 (every second number). The next remaining number is 3, so cross out all numbers greater than 3 that are divisible by 3 (every third number). The next remaining number is 5, so cross out all numbers greater than 5 that are divisible by 5 (every fifth number).

The numbers remaining after sieving with primes at most sqrt(n) are prime. The diagram above sieves up to 50 using primes at most |_sqrt(50)_|=7, where |_x_| is the floor function. If instead each multiple of every prime up to n is marked, including each prime itself and counting repeated markings, then the number of markings gives the number of distinct prime factors of each number.

The sieve of Eratosthenes can be used to compute the prime counting function pi(x). For a real number x>=2, let M_x be the product of all primes p<=sqrt(x), with M_x=1 when there are none. The inclusion-exclusion principle gives

 pi(x)=pi(sqrt(x))-1+sum_(d|M_x)mu(d)|_x/d_|,

where mu(d) is the Möbius function (Havil 2003, pp. 171-172; Oliveira e Silva 2006, pp. 760-761). The sum counts 1 together with the primes greater than sqrt(x) and at most x.

A sieve table in an Arabic manuscript of Nicomachus's Introduction to Arithmetic

Nicomachus preserved an ancient account of the sieve in Book I, Chapter 13 of his Introduction to Arithmetic (Nicomachus 1926). The table above, from an Arabic translation in British Library Add MS 7473, illustrates the transmission of this Greek method through the Arabic manuscript tradition (British Library).


See also

Inclusion-Exclusion Principle, Prime Number, Sieve, Sieve of Atkin

Explore with Wolfram|Alpha

References

British Library. "Al-Madkhal ilá 'ilm al-'adad." Nicomachus of Gerasa, Arabic translation, Add MS 7473, ff. 122r-164r. Qatar Digital Library. https://www.qdl.qa/en/archive/81055/vdc_100023677047.0x00000f.Conway, J. H. and Guy, R. K. The Book of Numbers. New York: Springer-Verlag, pp. 127-130, 1996.Derbyshire, J. Prime Obsession: Bernhard Riemann and the Greatest Unsolved Problem in Mathematics. New York: Penguin, pp. 100-101, 2004.Flannery, S. and Flannery, D. In Code: A Mathematical Journey. London, England: Profile Books, pp. 38-42, 2000.Gardner, M. The Sixth Book of Mathematical Games from Scientific American. Chicago, IL: University of Chicago Press, pp. 79-80, 1984.Haddon, M. The Curious Incident of the Dog in the Night-Time. New York: Vintage, pp. 11-12, 2003.Havil, J. "The Sieve of Eratosthenes." §15.5 in Gamma: Exploring Euler's Constant. Princeton, NJ: Princeton University Press, pp. 171-172, 2003.History of Mathematics Project. "The Sieve of Eratosthenes." https://www.history-of-mathematics.org/artifacts/sieve-of-eratosthenes.Nagell, T. "General Remarks. The Sieve of Eratosthenes." §15 in Introduction to Number Theory. New York: Wiley, pp. 51-54, 1951.Nicomachus of Gerasa. Introduction to Arithmetic (Trans. M. L. D'Ooge). New York: Macmillan, Book I, Ch. 13, 1926.Oliveira e Silva, T. "Computing pi(x): The Combinatorial Method." Revista do DETUA 4, 759-768, 2006. https://sweet.ua.pt/tos/bib/5.4.pdf.Pappas, T. The Joy of Mathematics. San Carlos, CA: Wide World Publ./Tetra, pp. 100-101, 1989.Ribenboim, P. The New Book of Prime Number Records. New York: Springer-Verlag, pp. 20-21, 1996.Séroul, R. "The Sieve of Eratosthenes." §8.6 in Programming for Mathematicians. Berlin, Germany: Springer-Verlag, pp. 169-175, 2000.Veritasium. "We're 99.9% Sure This Pattern Is True, but No One Can Prove It." Jun. 14, 2026. https://www.youtube.com/watch?v=8HBDE-msUjw.Wolfram, S. A New Kind of Science. Champaign, IL: Wolfram Media, p. 132, 2002.

Referenced on Wolfram|Alpha

Sieve of Eratosthenes

Cite this as:

Weisstein, Eric W. "Sieve of Eratosthenes." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/SieveofEratosthenes.html

Subject classifications