Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sieve of Atkin explanation

Tags:

I am doing a project at the moment and I need an efficient method for calculating prime numbers. I have used the sieve of Eratosthenes but, I have been searching around and have found that the sieve of Atkin is a more efficient method. I have found it difficult to find an explanation (that I have been able to understand!) of this method. How does it work? Example code (preferably in C or python) would be brilliant.

Edit: thanks for your help, the only thing that I still do not understand is what the x and y variables are referring to in the pseudo code. Could someone please shed some light on this for me?

like image 645
marc lincoln Avatar asked Jun 21 '09 12:06

marc lincoln


People also ask

What is the meaning of sieve of Eratosthenes?

: a procedure for finding prime numbers that involves writing down the odd numbers from 2 up in succession and crossing out every third number after 3, every fifth after 5 including those already crossed out, every seventh after 7, and so on with the numbers that are never crossed out being prime.

What is sieve technique in algorithm?

Definition. The sieve of Eratosthenes algorithm is an ancient algorithm that is used to find all the prime numbers less than given number T. It can be done using O(n*log(log(n))) operations. Using this algorithm we can eliminate all the numbers which are not prime and those that are less than given T.

When was the sieve of Eratosthenes created?

The most efficient way to find all of the small primes (say all those less than 10,000,000) is by using a sieve such as the Sieve of Eratosthenes(ca 240 BC): Make a list of all the integers less than or equal to n (and greater than one).

What is the complexity of sieve?

The classical Sieve of Eratosthenes algorithm takes O(N log (log N)) time to find all prime numbers less than N.


1 Answers

The wiki page is always a good place to start, since it explains the algorithm in full and provides commented pseudocode. (N.B. There's a lot of detail, and since the wiki website is reliably up, I won't quote it here.)

For references in the specific languages you mentioned:

  • C implementation (optimised)
  • Python implementation

Hope that helps.

like image 54
Noldorin Avatar answered Nov 25 '22 08:11

Noldorin