Objective
Computing base**exp % mod with huge numbers is infeasible if you multiply exp times. Fast exponentiation walks the bits of the exponent: it squares the base at each step and multiplies the result when the bit is 1, always working modulo mod.
Instructions
- The first line has the number
nof cases. Each case is a line withbase,expandmod. - Show
base**exp % modfor each case, without usingpowwith three arguments or the**operator on the full power.
3
2 10 1000
3 200 13
7 0 5
24
9
1
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise