Advertisement
Guest User

Modular exponentiation

a guest
May 13th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.14 KB | None | 0 0
  1. # compute B^E mod M
  2. def prodmodul(B, E, M):
  3.     buf=1
  4.     while E > 0:
  5.         buf=(buf * (( B**(E%10) ) % M) ) % M
  6.         B=(B**10) % M
  7.         E//=10L
  8.     return buf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement