adalah Python utama
def is_prime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
Mouad En-naciry
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
from math import sqrt
for i in range(2, int(sqrt(num)) + 1):
if num % i == 0:
print("Not Prime")
break
print("Prime")
# Note: Use this if your num is big (ex. 10000 or bigger) for efficiency
# The result is still the same if the num is smaller
def is_prime(n):
if n in (2, 3):
return True
if n <= 1 or not (n%6==1 or n%6==5):
return False
a, b= 5, 2
while a <= n**0.5:
if not n%a:
return False
a, b = a+b, 6-b
return True
# this method is much faster than checking every number because it uses the fact
# that every prime is either 1 above or 1 below a multiple of 6
# and that if a number has no prime factors, it has no factors at all
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 is_prime(n):
return bool(n&1)