How many multiplications does it take to compute x^n when n is a positive integer? It may be fewer than you think!

Worried that calling x ** 15 “slow” is not correct? Don’t worry, I tested!

In[4]: timeit.timeit(“100000 ** 15”)
Out[4]: 0.3686526000000043
In[5]: timeit.timeit(“pow_15_minimal(100000)”, globals=globals())
Out[5]: 0.3275107000000048

Source code: https://github.com/mCodingLLC/VideosS…

Subscribe: https://www.youtube.com/c/mCodingWithJamesMurphy/featured

Efficient Exponentiation
1.80 GEEK