Skip to main content

Fast Powering

Definition​

The Fast Powering Algorithm, also known as Exponentiation by Squaring, is a method used to efficiently compute large powers of a number. It reduces the number of multiplications required, making it significantly faster than the naive approach of repeated multiplication

Practice​

fast_power(x, n):
if n == 0:
return 1
else if n % 2 == 0:
temp = fast_power(x, n/2)
return temp * temp
else:
temp = fast_power(x, (n-1)/2)
return x * temp * temp