Skip to content

Add linear sieve algorithm#3098

Open
Monier-Ayman wants to merge 3 commits intoTheAlgorithms:masterfrom
Monier-Ayman:linear_sieve
Open

Add linear sieve algorithm#3098
Monier-Ayman wants to merge 3 commits intoTheAlgorithms:masterfrom
Monier-Ayman:linear_sieve

Conversation

@Monier-Ayman
Copy link

Description of Change

This PR adds the linear sieve algorithm to the math folder.
The algorithm finds all prime numbers up to N and calculates the smallest prime factor (SPF) for each number.
This is more efficient than the standard sieve for some applications.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one
  • I acknowledge that all my contributions will be made under the project's license

Notes

  • File added: math/linear_sieve.cpp
  • Main function contains an example that prints primes up to 50

@whileds
Copy link

whileds commented Feb 4, 2026

Nice implementation of linear sieve.
For TheAlgorithms guidelines, please avoid bits/stdc++.h, add proper Doxygen documentation, wrap code in a namespace, and include self-tests using assert() instead of printing output.

@Monier-Ayman
Copy link
Author

Nice implementation of linear sieve. For TheAlgorithms guidelines, please avoid bits/stdc++.h, add proper Doxygen documentation, wrap code in a namespace, and include self-tests using assert() instead of printing output.

Thanks for the review!
I’ve updated the linear sieve implementation to follow TheAlgorithms guidelines:

  • Removed bits/stdc++.h and used only the required headers.
  • Added full Doxygen documentation for the file and functions.
  • Wrapped the code inside a math namespace.
  • Updated self-tests to use assert() only, no printing.

Please let me know if anything else needs adjustment.

@Monier-Ayman
Copy link
Author

Hi @Panquesito7 and @realstealthninja,

When you have some time, could you please review this PR? I’ve updated the linear sieve to follow TheAlgorithms guidelines, and I’d really appreciate your feedback.

Thanks a lot!

@github-actions
Copy link
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Author has not responded to the comments for over 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants