The Miller-Rabin algorithm works as follows on input .
We assume is a positive odd integer.
It computes such that is the largest power
of dividing .
Then it picks random
. If
it outputs "composite."
Otherwise it computes the sequence
(3)
If the sequence (4) does not start with it outputs
"composite." If the first element in the
sequence which is not is not then it outputs
"composite." Otherwise it outputs "don't know."