Description
Implement pow(x, n), which calculates x raised to the power n (i.e., xⁿ). Use fast exponentiation for efficiency. Return the result as an integer.
Examples
Input:
x = 2.00000, n = 10Output:
1024.0Explanation:
2^10 = 1024.
Input:
x = 2.0, n = -2Output:
0.25Explanation:
2^(-2) = 1/(2^2) = 1/4 = 0.25. Negative exponent means taking the reciprocal.
Input:
x = -3.00000, n = 4Output:
81.0Explanation:
(-3)^4 = (-3) × (-3) × (-3) × (-3) = 81. When a negative number is raised to an even power, the result is positive.
Constraints
- •
-100.0 < x < 100.0 - •
-2³¹ ≤ n ≤ 2³¹ - 1