Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One quick method to generate a list of all prime numbers that are lesser than N is the Sieve of Eratosthenes:

  1. Create a list of all numbers from 2 to N.
  2. Start with the first prime number, 2, and cross out all multiples of 2 from the list (4, 6, 8, etc.).
  3. Move to the next unmarked number, 3, which is also prime, and cross out all multiples of 3 from the list (6, 9, 12, etc.).
  4. Continue this process, taking the next unmarked number as the next prime, and crossing out all its multiples.
  5. When you reach the square root of N, all remaining unmarked numbers are prime.

The resulting list will contain all prime numbers less than N.