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.
Input: base = 2, exponent = 10 Output: 1024
2^10 = 1024, which is already below 1000000007.
Input: base = 3, exponent = 0 Output: 1
Any number to the power 0 is 1.
0 <= base <= 10^90 <= exponent <= 10^15Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #641 Large Power Modulo. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.