Trace Algorithm 4 to compute 3^16 mod 13
ALGORITHM 4: Recursive Modular Exponentiation
Procedure mpower(b, n, m: integers with b > 0 and m ≥ 2, n ≥ 0)
If n = 0 then
return 1
Else if n is even then
return mpower(b, n/2, m)^2 mod m
Else
return (mpower(b, ⌈n/2⌉, m)^2 mod m · b mod m) mod m
{output is b^n mod m}