Modular Power
Return without using the built-in three-argument pow.
Requirements
- Run in multiplications using exponentiation by squaring:
Constraints
- ,
Examples
EXAMPLE WALKTHROUGH1024 mod 1000
A guided view of the published example, not a trace of your code.
INPUT
[2,10,1000]TASKmodular_power()
EXPECTED OUTPUT
24Start with the input values shown in this example.
Example 1 of 3
Input: a = 2, b = 10, m = 1000
Output: 24
Explanation: 1024 mod 1000
Input: a = 3, b = 0, m = 7
Output: 1
Explanation: zero exponent
Input: a = 7, b = 128, m = 13
Output: 3
Explanation: power of two exponent
Hint 1
Look at the bits of b from least to most significant, squaring the base each step.