Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def bin_pow_n(a, z, n):
- res = 1
- while(z):
- if (z & 1):
- res = res * (a % n) % n
- a *= a
- z >>= 1
- return res
- a = int(input('a = '), 10)
- z = int(input('z = '), 10)
- n = int(input('n = '), 10)
- x = bin_pow_n(a, z, n)
- print(f'a^z mod n = {x}')
RAW Paste Data