Skip to content

Instantly share code, notes, and snippets.

@MahmudHasanCSE
Created April 28, 2018 04:08
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 MahmudHasanCSE/b58553966c54865204554e175b609a5f to your computer and use it in GitHub Desktop.
Save MahmudHasanCSE/b58553966c54865204554e175b609a5f to your computer and use it in GitHub Desktop.
def pow(a, n): # a^n --- O(log n)
if n == 0: return 1
if n == 1: return a
if n % 2 == 1:
return a * pow(a, n-1)
else:
p = pow(a, n/2)
return p * p
print(pow(2, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment