Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5701 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 938 |
@bt8816103042 | 739 |
@SHOAIBVIJAPURE | 428 |
@codeantik | 412 |
@SherlockHolmes3 | 407 |
@neverevergiveup | 348 |
@mahlawatep | 347 |
@shalinibhataniya1097 | 343 |
@murarry3625 | 333 |
@saiujwal13083 | 326 |
@rohitanand | 314 |
Complete Leaderboard |
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
Your Task:
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
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes