Please enter your email address or userHandle.
For two given positive numbers a and b. Find ab. Output your number modulus 109+7.
Input: a = 1, b = 1
Explanation: 11 % (109+7) = 1
Input: a = 2, b = 5
Explanation: 25 % (109+7) = 32
You don't need to read input or print anything. Your task is to complete the function power() which takes a, b as inputs, and returns the answer.
Expected Time Complexity: O(log b)
Expected Auxiliary Space: O(1)
1 ≤ a ≤ 105
1 ≤ b ≤ 1016
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.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.