from sympy import isprime
isprime(23)
for i in range(2, 20):
for x in range(2, i):
if i % x == 0:
break
else:
print(i, "is a prime number")
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
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
def check_if_prime():
number = int(input("Enter number: "))
prime_lists = [1,2,3]
divisible_by = []
if number in prime_lists:
return divisible_by
if number==0:
return None
for i in range(2,number):
if number%i==0:
divisible_by.append(i)
return divisible_by
check_if_prime()
from math import sqrt, floor;
def is_prime(num):
if num < 2: return False;
if num == 2: return True;
if num % 2 == 0: return False;
for i in range(3,floor(sqrt(num))+1,2):
if num % i == 0: return False;
return True;