A satellite handshake computes a raised to a rolling counter, reduced modulo m. The counter b can be astronomically large, so it is supplied as a decimal string of up to 1000 digits. Compute (a ** b) mod m. Use the convention that a ** 0 = 1 for every a (including a = 0).
Line 1: two integers a and m.
Line 2: the exponent b as a non-negative decimal integer (it may have up to 1000 digits and may contain leading zeros).
A single integer: (a ** b) mod m.
Example 1
Input
2 1000 10
Expected
24
Explanation
2 to the 10th is 1024, and 1024 mod 1000 is 24.
Example 2
Input
3 7 5
Expected
5
Explanation
3 to the 5th is 243, and 243 mod 7 is 5.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →