How to Calculate x^n in Log Time (Fast Power Algorithm)

A beginner friendly approach to optimize pow(x, n)