Created
October 11, 2022 14:27
-
-
Save theabbie/b7fc6179c4af3b10a7181df469f7efe6 to your computer and use it in GitHub Desktop.
Iterative binary exponentiation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pow(a, b): | |
curr = a | |
res = 1 | |
while b: | |
if b & 1: | |
res *= curr | |
b = b >> 1 | |
curr *= curr | |
return res | |
print(pow(58, 595)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment