Fast Power
Return x raised to the whole number power n (with n >= 0) using repeated squaring, so that only about log n multiplications are needed. Do not use ** or pow.
Example 1
x 3
n 4
returns 81
81.
Constraints
-10 <= x <= 100 <= n <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Friday the 13th CountMedium
- Last Digit of a PowerMedium
- Last Person StandingMedium
- Minimum Moves to Equal ElementsMedium
- Multiply StringsMedium
- Power ModMedium
- Trailing Zeroes in FactorialMedium
- Twin PrimesMedium