def is_prime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
import math
def isPrimeNumber(n):
if (n < 2):
return False;
sq = int(math.sqrt(n))
for i in range(2, sq + 1):
if (n % i == 0):
return False
return True
def isPrime(n):
if n<2: #1, 0 and all negative numbers are not prime
return False
elif n==2: #2 is prime but cannot be calculated with the formula below becuase of the range function
return True
else:
for i in range(2, n):
if (n % i) == 0: #if you can precisely divide a number by another number, it is not prime
return False
return True #if the progam dont return False and arrives here, it means it has checked all the numebrs smaller than n and nono of them divides n. So n is prime
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;
def is_prime(n):
return bool(n&1)