In preparation for computing with Fermat's little theorem
and Euler's theorem, both of which will be stated later,
we show how to efficiently compute the power of an integer modulo
.
One way to compute
modulo
is simply to compte
then to reduce modulo
. This is relatively hard to do if
is
large since there are a lot of digits to keep track of.
An alternative method is given below.
To compute
modulo
:
step 1: write
is binary,
step 2: Compute
step 3: Compute
.