def is_prime(p):
    """
    Returns True if p is a prime

    This function uses Fermat's little theorem to quickly remove most
    candidates.

    https://en.wikipedia.org/wiki/Fermat%27s_little_theorem
    """
    if p == 2:
        return True
    elif p <= 1 or p % 2 == 0 or 2**(p-1) % p != 1:
        return False
    return all(p % n != 0 for n in range(3,int(p ** 0.5 + 1),2))