import math


def prime(n):
    """Primality test by trial division."""
    if n == 2:
        return True
    elif n < 2 or n % 2 == 0:
        return False
    else:
        return not any(n % x == 0
                       for x in range(3, math.ceil(math.sqrt(n)) + 1, 2))