Optimize perfect cube detection for large numbers with modular check#12981
Closed
lighting9999 wants to merge 5 commits intoTheAlgorithms:masterfrom
Closed
Optimize perfect cube detection for large numbers with modular check#12981lighting9999 wants to merge 5 commits intoTheAlgorithms:masterfrom
lighting9999 wants to merge 5 commits intoTheAlgorithms:masterfrom
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
Contributor
Author
|
@cclauss Can you help me review the PR? |
cclauss
reviewed
Sep 19, 2025
Member
|
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. |
lighting9999
commented
Sep 20, 2025
Contributor
Author
lighting9999
left a comment
There was a problem hiding this comment.
I have just completed the suggested changes, what should I do now?
mindaugl
approved these changes
Sep 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Checklist: