me30

bin_pow_n.py

Nov 24th, 2020
605
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2.  
  3. def bin_pow_n(a, z, n):
  4.     res = 1
  5.     while(z):
  6.         if (z & 1):
  7.             res = res * (a % n) % n
  8.         a *= a
  9.         z >>= 1
  10.     return res
  11.  
  12. a = int(input('a = '), 10)
  13. z = int(input('z = '), 10)
  14. n = int(input('n = '), 10)
  15. x = bin_pow_n(a, z, n)
  16. print(f'a^z mod n = {x}')
RAW Paste Data