What is the Sieve of Eratosthenes?
It is a simple and ancient method for finding all Prime numbers less than or equal to N.
Algorithm to find Prime numbers by Sieve of Eratosthenes
- Initially, we will create a boolean array of size equal to the N and mark each position in the array True.
- We initialize a variable p as 2. If the variable is prime then mark each multiple of number False in the array and update the variable p by increment.
- Repeat step 2 until the square of the variable p is less than or equal to N.
- Return, the elements in the array with True contains all Prime numbers.
Implementation of the above algorithm using python program
Output
need an explanation for this answer? contact us directly to get an explanation for this answer