Description

Implement pow(x, n), which calculates x raised to the power n (i.e., x^n). Handle negative exponents and optimize for O(log n) time complexity.

Examples

Input:x = 2.00000, n = 10
Output:1024.00000
Explanation:

2^10 = 1024.

Input:x = 2.10000, n = 3
Output:9.26100
Explanation:

2.1^3 = 9.261.

Input:x = 2.00000, n = -2
Output:0.25000
Explanation:

2^-2 = 1/(2^2) = 0.25.

Constraints

  • -100.0 < x < 100.0
  • -2³¹ ≤ n ≤ 2³¹ - 1
  • n is an integer.
  • -10⁴ ≤ x^n ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!