Skip to content

Commit

Permalink
Modular Exponentiation in Python
Browse files Browse the repository at this point in the history
By the way, it's in-built in Python :D
  • Loading branch information
detel committed Jul 22, 2015
1 parent a5583a7 commit 9a841ce
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MOD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Calculate (x ** y) % z efficiently.
def pow_mod(x, y, z):
number = 1
while y:
if y & 1:
number = number * x % z
y >>= 1
x = x * x % z
return number

0 comments on commit 9a841ce

Please sign in to comment.