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"
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