Sieve of Eratosthenes Calculator
Last updated: October 3, 2023
Are you looking for a quick and efficient way to find all prime numbers within a given range? Look no further than the Sieve of Eratosthenes calculator. This ancient algorithm, attributed to the Greek mathematician Eratosthenes of Cyrene, has stood the test of time and remains a powerful tool for generating prime numbers.
What is the Sieve of Eratosthenes?
The Sieve of Eratosthenes is an ancient algorithm devised to find all prime numbers up to a specified limit. Its beauty lies in its simplicity and efficiency. Unlike many other prime-finding methods, the Sieve of Eratosthenes eliminates non-prime numbers directly, leaving you with a list of prime numbers.
The Algorithm
Step 1: Create a List of Integers
Start by creating a list of integers from 2 to your specified upper limit. This list represents all potential prime numbers.
Step 2: Mark Multiples
Begin with the first number in your list (2), which is a prime number. Cross out all multiples of 2, as they are not prime. Move to the next unmarked number (3) and cross out all multiples of 3. Repeat this process for each unmarked number, always starting with the smallest unmarked number you encounter.
Step 3: Repeat Until Completion
Continue marking and eliminating multiples until you reach a point where the square of the next unmarked number exceeds the specified upper limit. At this point, all remaining unmarked numbers are prime.
Step 4: List the Primes
Your list of prime numbers is now complete. You have successfully applied the Sieve of Eratosthenes!
Sieve of Eratosthenes Examples
Let’s walk through a couple of examples to illustrate how the Sieve of Eratosthenes works.
Example 1: Finding Primes Up to 20
- Create a list of integers from 2 to 20:
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
- Start with 2, the first prime number. Cross out multiples of 2:
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
- Move to the next unmarked number, 3, and cross out multiples:
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
- Continue for 5 and 7. You’ll be left with [2, 3, 5, 7, 11, 13, 17, 19].
The prime numbers up to 20 are 2, 3, 5, 7, 11, 13, 17, and 19
Example 2: Finding Primes Up to 50
- Create a list of integers from 2 to 50.
- Start with 2, cross out multiples.
- Move to 3, cross out multiples.
- Continue this process until you reach the square root of 50.
The prime numbers up to 50 are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, and 47.
Sieve of Eratosthenes video
Page views: 939