Sieve of Eratosthenes

DOWNLOAD Mathematica Notebook EratosthenesSieve

An algorithm for making tables of primes. Sequentially write down the integers from 2 to the highest number n you wish to include in the table. Cross out all numbers >2 which are divisible by 2 (every second number). Find the smallest remaining number >2. It is 3. So cross out all numbers >3 which are divisible by 3 (every third number). Find the smallest remaining number >3. It is 5. So cross out all numbers >5 which are divisible by 5 (every fifth number).

Continue until you have crossed out all numbers divisible by |_sqrt(n)_|, where |_x_| is the floor function. The numbers remaining are prime. This procedure is illustrated in the above diagram which sieves up to 50, and therefore crosses out composite numbers up to |_sqrt(50)_|=7. If the procedure is then continued up to n, then the number of cross-outs gives the number of distinct prime factors of each number.

The sieve of Eratosthenes can be used to compute the prime counting function as

 pi(x)=pi(sqrt(x))+1+x-|_1/2x_|-|_1/3x_|-|_1/5x_|-...+|_x/(2·3)_|+|_x/(2·5)_|+|_x/(3...5)_|+...-|_x/(2·3·5)_|+...

which is essentially an application of the inclusion-exclusion principle (Havil 2003, pp. 171-172).

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.