Guest User

Modular exponentiation

a guest
May 13th, 2017
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data