+ 1
Can someone explain how sieve of eratosthenes algorithm works and segmented sieve too?
Sieve of eratosthenes algorithm is used for finding prime numbers with very efficient time complexity. This is a link to algorithm http://www.geeksforgeeks.org/sieve-of-eratosthenes/
1 Resposta
+ 1
This algorithm gives you all prime numbers from 2 to determined P.
1) Set all numbers from 2 to P to list.
2) Set current variable n=2 (this is the smallest prime number).
3) Remove from this list all numbers that are multiples of current n.
4) Set new value for variable n: next number of updated list after current n.
5) Repeat operations #3 and then #4.
Finally you'll get a list with only prime numbers.