from math import gcd
from random import randrange


def fermat_primality_test(n: int, k: int = 3) -> bool:
    """
    https://en.wikipedia.org/wiki/Fermat_primality_test

    >>> assert all(fermat_primality_test(i) for i in [2, 3, 5, 7, 11])
    >>> assert not all(fermat_primality_test(i) for i in [4, 6, 8, 9, 10])
    """
    for _ in range(k):
        random_num = randrange(1, n)
        if gcd(n, random_num) != 1 or pow(random_num, n - 1, n) != 1:
            return False
    return True