Skip to content

Conversation

lighting9999
Copy link
Contributor

@lighting9999 lighting9999 commented Sep 19, 2025

  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

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

… 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
@lighting9999 lighting9999 changed the title Optimize perfect cube detection for large numbers with modular checks… Optimize perfect cube detection for large numbers with modular check Sep 19, 2025
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Sep 19, 2025
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Sep 19, 2025
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Sep 19, 2025
@lighting9999
Copy link
Contributor Author

@cclauss Can you help me review the PR?

@cclauss
Copy link
Member

cclauss commented Sep 19, 2025

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.

Copy link
Contributor Author

@lighting9999 lighting9999 left a 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants