The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N

Lecture



Sieve of Atkin — an algorithm for finding all prime numbers up to a given integer N. The algorithm was created by A. O. L. Atkin and D. J. Bernstein . The asymptotic running time claimed by the authors matches the speed of the best previously known sieving algorithms, but compared to them the Sieve of Atkin requires less memory.

Description

The main idea of the algorithm consists in using irreducible quadratic forms (representing numbers as ax2 + by2). Previous algorithms were mostly various modifications of the Sieve of Eratosthenes, which used a representation of numbers as reduced forms (typically as a product xy).

In simplified form, the algorithm can be presented as follows:

  • All numbers congruent (mod 60) to 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56 or 58 are divisible by 2 and therefore certainly not prime. All numbers congruent (mod 60) to 3, 9, 15, 21, 27, 33, 39, 45, 51 or 57 are divisible by 3 and are also not prime. All numbers congruent (mod 60) to 5, 25, 35 or 55 are divisible by 5 and are also not prime. All these residues (mod 60) are ignored.
    • All numbers congruent (mod 60) to 1, 13, 17, 29, 37, 41, 49 or 53 have a remainder of 1 when divided by 4. These numbers are prime if and only if the number of solutions of the equation 4x2 + y2 = n is odd and the number itself is not divisible by the square of any prime number (en:square-free integer).
    • Numbers congruent (mod 60) to 7, 19, 31, or 43 have a remainder of 1 when divided by 6. These numbers are prime if and only if the number of solutions of the equation 3x2 + y2 = n is odd and the number itself is not divisible by the square of any prime.
    • Numbers congruent (mod 60) to 11, 23, 47, or 59 have a remainder of 11 when divided by 12. These numbers are prime if and only if the number of solutions of the equation 3x2y2 = n (for x > y) is odd and the number n itself is not divisible by the square of any prime.
    • A separate step of the algorithm crosses out numbers that are multiples of squares of primes. Since none of the numbers under consideration is divisible by 2, 3, or 5, they are accordingly not divisible by their squares either. Therefore checking that a number is not a multiple of the square of a prime number does not need to include 22, 32, and 52.

Segmentation

To reduce memory requirements, «sieving» is carried out in portions (segments, blocks), whose size is approximately The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N.

Pre-sieving

To speed up the work, the algorithm ignores all numbers that are multiples of one of several of the first primes (2, 3, 5, 7, …). This is done by using standard data structures and processing algorithms proposed earlier by Paul Pritchard (English: Paul Pritchard) . They are known as English: wheel sieving. The number of first primes chosen depends on the given number N. Theoretically it is suggested to take the first primes up to approximately The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N. This makes it possible to improve the asymptotic estimate of the algorithm's speed by a factor of The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N. This, however, requires additional memory, which as N grows is bounded as The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N. The increase in memory requirements is estimated as The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N.

The version presented on one of the authors' website , is optimized for finding all prime numbers up to one billion (The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N); it excludes from the calculations numbers divisible by 2, 3, 5 and 7 (2 × 3 × 5 × 7 = 210).

Complexity estimate

According to the authors' estimate , the algorithm has asymptotic complexity The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N and requires The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N bits of memory. Previously, algorithms were known that were equally asymptotically fast but required substantially more memory . In theory, this algorithm combines maximum speed with the lowest memory requirements. The implementation of the algorithm made by one of the authors shows a fairly high practical speed .

The algorithm uses two kinds of optimization that substantially increase its efficiency (compared to the simplified version).

Below is an implementation of the simplified version in the C programming language, illustrating the main idea of the algorithm — the use of quadratic forms:

 The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N

The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N

Version of the algorithm in Pasca

 The Sieve of Atkin — an Algorithm for Finding All Prime Numbers up to a Given Integer N

See also

  • Sieve of Eratosthenes
  • Sieve of Sundaram
  • [[b9849]]

See also

created: 2020-12-10
updated: 2026-03-10
346



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Stereometry"

Terms: Stereometry