UF6

Dismath

UF6
May 5th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def modexp(a, n, m):
  2.     b = []
  3.     while n:
  4.         b.append(n%2)
  5.         n /= 2
  6.     power = 1
  7.     b.reverse()
  8.     for x in b:
  9.         power = (power*power)%m
  10.         if x:
  11.             power = (power*a)%m
  12.     return power
  13.  
  14. print (modexp (2,34, pow(10,10)))
  15. print (modexp (2,pow(10,20), pow(10,10)))
Add Comment
Please, Sign In to add comment