Skip to content

Add Sieve of Atkin algorithm for efficient prime generation - #12974

Merged
cclauss merged 6 commits into
TheAlgorithms:masterfrom
AyhamJo7:add-sieve-of-atkin
Sep 8, 2026
Merged

Add Sieve of Atkin algorithm for efficient prime generation#12974
cclauss merged 6 commits into
TheAlgorithms:masterfrom
AyhamJo7:add-sieve-of-atkin

Conversation

@AyhamJo7

@AyhamJo7 AyhamJo7 commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

This PR adds an implementation of the Sieve of Atkin algorithm to the maths directory.

@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Sep 17, 2025
Implement the Sieve of Atkin algorithm as an alternative to the existing
Sieve of Eratosthenes. This modern algorithm offers better theoretical
complexity O(n / log log n) and uses quadratic forms for prime detection.

Features:
- Comprehensive docstring with algorithm explanation
- Type hints and input validation
- Extensive doctests covering edge cases
- Follows repository coding conventions
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Sep 17, 2025
@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Sep 17, 2025

@priya-sundaram-dev priya-sundaram-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed as part of the maths/ awaiting-reviews triage (#15081).

Verdict: correct algorithm, genuinely new — recommend merge after removing one stray file.

Not a duplicate. We have several Eratosthenes-family sieves (sieve_of_eratosthenes.py, prime_sieve_eratosthenes.py, segmented_sieve.py, odd_sieve.py), but the Sieve of Atkin is a genuinely different algorithm (quadratic-form based, not trial-marking of multiples), so it passes the no-duplicate bar.

Correctness — verified. I diffed the output against an independent Eratosthenes reference for every limit 0–400 plus 1000, 5000, 10007, 50000, 100000: identical prime sets, 0 discrepancies. Edge cases (0, 1, 2, negative → ValueError) all match the doctests.

One change required before merge:

  1. Remove pr_description.txt — it's a PR-writeup file that shouldn't be committed to the repo. Only maths/sieve_of_atkin.py should ship. (This is likely also why a reviewer would hesitate; drop it and the PR is a single clean module.)

Optional polish (non-blocking):
2. The docstring's O(n / log log n) refers to the theoretical optimized Atkin; this straightforward list-of-bools implementation is closer to O(n) work with a smaller constant than a segmented/wheel version. A one-line "this is the basic, non-segmented form" note would set reader expectations accurately.

Clean, well-documented, good doctest coverage on the edge cases. Just drop the stray .txt and this is ready.

@cclauss cclauss added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Sep 8, 2026
@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Sep 8, 2026
Added additional explanation about the Sieve of Atkin algorithm.
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 8, 2026
@cclauss
cclauss merged commit 3374ede into TheAlgorithms:master Sep 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants