Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
Exponentiation (Set 2)
Easy Accuracy: 20.34% Submissions: 1012 Points: 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

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Exponentiation (Set 2)

Output Window