solulubeta
Sign in
Recursion & Memo / See it, then write it
01.09 · Problem

Fast Power

Medium Shrink by n / 2 Pro

Return xⁿ modulo 1,000,000,007. n can be as large as 10¹⁸, so going down one step at a time is far too slow. Halve n instead.

Examples

Example 1

Input:  x = 2, n = 10
Output: 1024

Example 2

Input:  x = 3, n = 0
Output: 1
solulu Pro

Continue this problem with Pro

Inside: step-by-step hints · 12 hidden tests · reference solutions · code editor.

Lifetime ₹1,999 ₹999 · Launch offer
Mark this problem as solved when you are finished.

Item 9 of 44 · updated 2026-10-13