Given two non-negative integers base and exp, compute base^exp (base raised to the power of exp) using recursion.
Use fast exponentiation (also called exponentiation by squaring):
exp is 0, return 1exp is even, power(base, exp) = power(base, exp / 2) * power(base, exp / 2)exp is odd, power(base, exp) = base * power(base, exp - 1)To avoid redundant computation, compute power(base, exp / 2) once and square the result.
You must solve this problem recursively — do not use loops or built-in power functions.
base = 2, exp = 101024base = 3, exp = 01base = 5, exp = 31250 <= base <= 1000 <= exp <= 30The result fits in a 64-bit integer.You must use recursion (no loops or built-in power functions).Run your code to see results
Use Cmd+Enter to run