Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Find (a^b)%m
Easy Accuracy: 1.97% Submissions: 151 Points: 2

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.

Example 1:

Input:
a = "3", b = 2, m = 4
Output:
1
Explanation:
(3^2)%4 = 9%4 = 1

Example 2:

Input:
a = "8", b = 2, m = 6
Output:
4
Explanation:
(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)

Constraints:
1 <= |a| <= 105
0 <= b <= 109
1 <= m <=109

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Find (a^b)%m