I am working with modular exponentiation and my code compiles, but I am not sure where my formula is wrong or is it maybe cause im doing int instead of long ? but im running 3.3.0 python so i should use int...if someone could help please...thank you
for example im trying to
find 7 644 mod 645 which answer should be 436
find 11 644 mod 645 which answer should be 1
find 3 2003 mod 99 which answer should be 27
find 123 1001 mod 101 which answer should be 22
the only one I have correct is the last one which is 22
here is what i have
for example im trying to
find 7 644 mod 645 which answer should be 436
find 11 644 mod 645 which answer should be 1
find 3 2003 mod 99 which answer should be 27
find 123 1001 mod 101 which answer should be 22
the only one I have correct is the last one which is 22
here is what i have
def me(b, n, m):
a = bin(n)[:1:-1]
x = 1
power = int(B)/> % int(m)
for i in range(len(a)):
if a[i] == '1':
x = (x * power) % m
power = (power * power) % m
return str(x)
print (me(7, 644, 645))
print (me(11, 644, 645))
print (me(3, 2003, 99))
print (me(123, 1001, 101))