THE MILLER–RABIN TEST

The Fermat and Solovay–Strassen tests are each based on translating a congruence modulo prime numbers, either Fermat’s little theorem or Euler’s congruence, over to the setting of composite numbers and hoping to make it fail there. The Miller–Rabin test uses a similar idea, but involves a system of congruences. For an odd integer n > 1, factor out the largest power of 2 from n− 1, say n− 1 = 2ek where e ≥ 1 and k is odd. This meaning for e and k will be used throughout. The polynomial xn−1 − 1 = x2ek − 1 can be factored repeatedly as often as we have powers of 2 in the exponent: