Skip to main content

Module primality

Module primality 

Source
Expand description

Deterministic primality testing for 64-bit integers.

See the book entry Primes: sieves, Miller–Rabin and factorisation.

Functions§

is_prime
Deterministic primality for every u64: Miller-Rabin with the first twelve prime bases, whose smallest common strong pseudoprime is 318 665 857 834 031 151 167 461 ≈ 3.2 · 10²³ (Sorenson and Webster, 2015), far above u64::MAX ≈ 1.8 · 10¹⁹, after trial division by small primes.
is_strong_probable_prime
Whether n passes the Miller-Rabin strong probable-prime test to base a.
mul_mod
a · b mod m without overflow.
next_prime
The smallest prime ≥ n (None past the largest 64-bit prime).
pow_mod
base^exponent mod m by binary exponentiation (m > 0).