I'm playing around with https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
I want to test if a uint64_t
is prime or not. For that I need to compute pow(a, b) % n
where a <= 37
but b
and n
can be large uint64_t
values. I know I can compute pow(a, b)
with the square-and-multiply algorithm doing % n
in every step. But that still leaves 2 problematic operations: (x * x) % n
and (x * a) % n
.
I wonder if there is something better than splitting everything into low and high 32bit and doing long multiplication and long division for the remainder.
PS: don't assume there is a 128bit integer type