45# include <initializer_list>
64 uint64_t d,
int s)
noexcept
67 if (x == 1 or x == n - 1)
69 for (
int r = 1;
r < s;
r++)
90 if (n < 2)
return false;
91 if (n == 2 or n == 3)
return true;
92 if (n % 2 == 0)
return false;
104 for (uint64_t a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022})
Safe modular arithmetic, extended Euclidean algorithm, and Chinese Remainder Theorem.
bool check_composite(uint64_t n, uint64_t a, uint64_t d, int s) noexcept
Helper function for Miller-Rabin test.
Main namespace for Aleph-w library functions.
bool miller_rabin(uint64_t n) noexcept
Miller-Rabin primality test for 64-bit integers.
uint64_t mod_exp(uint64_t base, uint64_t exp, const uint64_t m)
Modular exponentiation.
uint64_t mod_mul(uint64_t a, uint64_t b, uint64_t m)
Safe 64-bit modular multiplication.