-
-
Notifications
You must be signed in to change notification settings - Fork 48.2k
Optimize perfect cube detection for large numbers with modular check #12981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… and improved boundary estimation 1. Added modular arithmetic checks to quickly eliminate numbers that cannot be perfect cubes: · Last digit check: Only digits 0-9 can be cube endings · Modulo 7 check: Cubes can only be 0, 1, or 6 mod 7 · Modulo 9 check: Cubes can only be 0, 1, or 8 mod 9 2. Improved boundary estimation for very large numbers (n > 10^18): · Uses logarithmic approximation to calculate a reasonable upper bound · Reduces the binary search space significantly for extremely large values 3. Optimized computation in the binary search loop: · Added a check to avoid expensive cubic calculations for very large mid values · Uses integer division to prevent overflow in comparisons 4. Enhanced test coverage with comprehensive doctests: · Added tests for very large numbers (up to 10^300) · Included edge cases and error conditions · Maintained compatibility with existing tests
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@cclauss Can you help me review the PR? |
As discussed in CONTRIBUTING.md, do not add tests and code in the same pull request. First, create a pull request that adds tests to the existing algorithm. After that has landed, create a second pull request that changes the algorithm and modifies test results where the new algorithm generated different results than the old algorithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just completed the suggested changes, what should I do now?
Describe your change:
Checklist: