Please enter your email address or userHandle.
Given three numbers a, b and m. The task is to find (a^b)%m.
Note: a is given as a String because it can be very big.
a = "3", b = 2, m = 4
(3^2)%4 = 9%4 = 1
a = "8", b = 2, m = 6
(8^2)%6 = 64%6 = 4
You don't need to read input or print anything. Your task is to complete the function powerMod() which takes a string a and 2 integers b, and m as input and returns (ab % m).
Expected Time Complexity: O(Number of digits in a)
Expected Auxiliary Space: O(1)
1 <= |a| <= 105
0 <= b <= 109
1 <= m <=109
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
want to view the editorial?
Login to access your submissions.