Implement pow(x, n) % M.
In other words, given x, n and M, find (xn) % M.
Input: 3 2 4 Output: 1
Input: 10 9 6 Output: 4
You don't need to read or print anything. Your task is to complete the function PowMod() which takes the x, n and M as input parameters and returns xn % M.
Expected Time Complexity: O(log(n))
Expected Space Complexity: O(1)
1 <= x, n, M <= 100000
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.