Implement pow(x, n), which calculates x raised to the power n (i.e., x^n). Use the fast exponentiation algorithm to achieve O(log n) time complexity.
Calculate 2^10 using fast exponentiation
210
2
10
1
Fast Exponentiation (Binary):
x^n = (x²)^(n/2) if n is even
x^n = x × (x²)^((n-1)/2) if n is odd
Time: O(log n) instead of O(n)