Skip to content

Refactor PrimeFactorization: Miller-Rabin, simplify, add tests#1312

Merged
williamfiset merged 1 commit intomasterfrom
refactor-prime-factorization
Apr 1, 2026
Merged

Refactor PrimeFactorization: Miller-Rabin, simplify, add tests#1312
williamfiset merged 1 commit intomasterfrom
refactor-prime-factorization

Conversation

@williamfiset
Copy link
Copy Markdown
Owner

Summary

  • Replace trial-division isPrime (O(√n)) with deterministic Miller-Rabin (O(k log²n)), using 12 witnesses correct for all long values
  • Replace PriorityQueue-based loop with simple recursive factor method
  • Add overflow-safe mulMod and powMod for modular arithmetic on large values
  • Use mulMod in Pollard's rho to avoid overflow on large inputs
  • Add Javadoc, apply single-line body formatting rule
  • Time complexity is now truly O(n^(1/4)) expected per factor found
  • Add 11 JUnit 5 tests: small primes, prime powers, composites, large prime, large semiprime, product verification, edge cases

Test plan

  • bazel test //src/test/java/com/williamfiset/algorithms/math:PrimeFactorizationTest — 11 tests pass

🤖 Generated with Claude Code

…er-Rabin, add tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@williamfiset williamfiset merged commit 92284a1 into master Apr 1, 2026
2 checks passed
@williamfiset williamfiset deleted the refactor-prime-factorization branch April 1, 2026 04:21
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.

1 participant