Skip to content
Onsite

Power n^m

EasyP2Coding

Return n raised to the power m using recursion. Treat 0^0 as 1.

A version that multiplies m times works, but aim for the faster one that halves m on each call.

Example 1

Input
n = 2, m = 10
Output
1024
Why
2^10 = 1024.

Example 2

Input
n = 5, m = 0
Output
1

Example 3

Input
n = 0, m = 0
Output
1

Constraints

  • -100 <= n <= 100
  • 0 <= m <= 10^6
  • The result fits in a 53-bit integer (|result| < 2^53).

Hints

Run checks the 3 visible tests, Submit all 10.