""" Recursive function to compute large exponents fast. Rather than computing n multiplications of x, we recursively half the exponent, effectively creating O(log n) time complexity. """ def power(x, n): if n == 1: return x elif n%2 == 0: return power(x**2, n/2) else: return x*power(x**2, (n-1)/2)