Skip to content

Instantly share code, notes, and snippets.

@kendallm
Created October 18, 2020 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendallm/33d6fd141cb074475eb1d5ea47ba8569 to your computer and use it in GitHub Desktop.
Save kendallm/33d6fd141cb074475eb1d5ea47ba8569 to your computer and use it in GitHub Desktop.
Fast exponentiation
def pow(x, y):
if y == 0:
return 1
z = pow(x, y//2)
if y % 2 == 0:
return z * z
return x * z * z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment