📜  如何在python代码示例中查看数字是否为素数

📅  最后修改于: 2022-03-11 14:46:18.630000             🧑  作者: Mango

代码示例2
def is_prime(n: int) -> bool:
    """Primality test using 6k+-1 optimization."""
    if n <= 3:
        return n > 1
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i ** 2 <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True