Skip to main content

Module primes

Module primes 

Source
Expand description

Primality and factorization. is_prime is a deterministic Miller–Rabin (the witness set {2,3,5,…,37} is proven correct for all of u64), and prime_factors uses trial division for small factors then Pollard’s rho (Brent’s variant) for the rest, so factorization is correct across the full u64 range — not just up to √n.

Functions§

divisors
All positive divisors of n, ascending. [1] for n = 1; empty for n = 0.
is_prime
Deterministic Miller–Rabin primality test, exact for all u64.
next_prime
The smallest prime strictly greater than n.
prime_factors
Prime factorization as (prime, exponent) pairs, ascending by prime. Empty for n < 2 (0 and 1 have no prime factorization).