Skip to the code
+25 XP

#641 Large Power Modulo

medium

A key-generation demo needs base raised to a huge exponent. The number is far too big to store, so the demo only shows its remainder.

Write powerMod(base, exponent) that returns base^exponent modulo 1000000007. By convention 0^0 is 1.

Example 1

Input: base = 2, exponent = 10
Output: 1024

2^10 = 1024, which is already below 1000000007.

Example 2

Input: base = 3, exponent = 0
Output: 1

Any number to the power 0 is 1.

Constraints

  • 0 <= base <= 10^9
  • 0 <= exponent <= 10^15
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).