python program to show the usage of fermat s little theorem in a division according to fermat s little theorem a b mod p always equals a b p 2 mod p here we assume that p is a prime number b divides a and p doesn t divide b wikipedia reference https en wikipedia orgwikifermat27slittletheorem a prime number using binary exponentiation function ologp using python operators python program to show the usage of fermat s little theorem in a division according to fermat s little theorem a b mod p always equals a b p 2 mod p here we assume that p is a prime number b divides a and p doesn t divide b wikipedia reference https en wikipedia org wiki fermat 27s_little_theorem a prime number using binary exponentiation function o log p using python operators
def binary_exponentiation(a: int, n: float, mod: int) -> int:
    if n == 0:
        return 1

    elif n % 2 == 1:
        return (binary_exponentiation(a, n - 1, mod) * a) % mod

    else:
        b = binary_exponentiation(a, n / 2, mod)
        return (b * b) % mod



p = 701

a = 1000000000
b = 10


print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p)


print((a / b) % p == (a * b ** (p - 2)) % p)