44# include <initializer_list>
66 if (x == 1
or x == n - 1)
68 for (
int r = 1;
r < s;
r++)
89 if (n < 2)
return false;
90 if (n == 2
or n == 3)
return true;
91 if (n % 2 == 0)
return false;
103 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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.