Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

check for prime in python

def is_prime(n: int) -> bool:
    """Primality test using 6k+-1 optimization."""
    import math
    if n <= 3:
        return n > 1
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i <= math.sqrt(n):
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True
Source by en.wikipedia.org #
 
PREVIOUS NEXT
Tagged: #check #prime #python
ADD COMMENT
Topic
Name
5+3 =