1# Time Efficient Primality Check in Python
2
3def primeCheck(n):
4 # 0, 1, even numbers greater than 2 are NOT PRIME
5 if n==1 or n==0 or (n % 2 == 0 and n > 2):
6 return "Not prime"
7 else:
8 # Not prime if divisable by another number less
9 # or equal to the square root of itself.
10 # n**(1/2) returns square root of n
11 for i in range(3, int(n**(1/2))+1, 2):
12 if n%i == 0:
13 return "Not prime"
14 return "Prime"
1import math
2def prime(x):
3 if x == 2 or x == 3 or x==5:
4 return True
5 if x == 1 or x == 4:
6 return False
7 num = 2
8 a= math.sqrt(x)+4
9 while a > num:
10 if x % num == 0:
11 return False
12 else:
13 num = num + 1
14 return True
1#make the function
2#to do this all hte vairibles go in side the function
3
4def CheckIfPrime ():
5 a1 = input("which number do you want to check")
6 a = int(a1)#you need the checking number as an int not an str
7 b = 2 #the number to check againts
8 c = ("yes")
9 while b < a:#run the loop
10 if a%b == 0:#check if the division has a remainder
11 c = ("no")#set the answer
12 b = b+1
13 print(c)#print the output
14CheckIfPrime ()#call the function
15
1def is_prime(n: int) -> bool:
2 """Primality test using 6k+-1 optimization."""
3 if n <= 3:
4 return n > 1
5 if n % 2 == 0 or n % 3 == 0:
6 return False
7 i = 5
8 while i ** 2 <= n:
9 if n % i == 0 or n % (i + 2) == 0:
10 return False
11 i += 6
12 return True
13