class Solution:
    def pow(self, x, n):
        if n == 0:
            return 1
        if n < 0:
            n *= -1
            x = 1/x
        # return x * pow(x, n - 1)
        return pow(x*x, n // 2) if n % 2 == 0 else x * pow(x * x, n // 2)

solution = Solution()
print(solution.pow(2, 3))