Timer is Running

Exponentiation (Set 2)
Submissions: 78   Accuracy:

2.57%

  Difficulty: Easy   Marks: 2

For two given positive numbers a and b. Find ab. Output your number modulus 109+7.

Example 1:

Input: a = 1, b = 1
Output: 1
Explanation: 11 % (109+7) = 1

Example 2:

Input: a = 2, b = 5
Output: 32
Explanation: 25 % (109+7) = 32

Your Task:  
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)

Constraints:
1 ≤ a ≤ 105
1 ≤ b ≤ 1016

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: souradeep
Author: abhiraj26


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.