Created
September 16, 2020 08:09
-
-
Save WinnerOK/daca5ae1dc864de5faedd9f032db669a to your computer and use it in GitHub Desktop.
Simple square-multiply exponentiation
This file contains 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
base, exp, mod = list(map(int, input("Enter base power mod: ").split())) | |
r = 1 | |
for i in bin(exp)[2:]: | |
bit = int(i) | |
r = (r * r) % mod | |
if bit == 1: | |
r = (r * base) % mod | |
print(f"Answer: {r}\nr == (base ** exp) % mod: {r == (base ** exp) % mod}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment