# fermat's little theorem
# a^(p-1) = 1 mod p   when p is prime and a is not multiple of p

p = 13
for a in [2, 5, 7, 10]:
    r = pow(a, p-1, p)
    print(a, "^", p-1, "mod", p, "=", r)


# using it to find inverse : a^(p-2) mod p
a = 5
inv = pow(a, p-2, p)
print("inverse of 5 mod 13 is", inv)
print("check 5 *", inv, "mod 13 =", (5*inv) % 13)

# not prime example
n = 12
print("2^11 mod 12 =", pow(2, 11, 12), "(not 1 because 12 is not prime)")
