FASTEST WAY TO CHECK WHETHER A NUMBER IS PRIME OR NOT
def isprime(n):
if n == 2:
return True
if n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i=5
w=2
while i * i <= n:
if n % i == 0:
return False
i+=w
w=6-w
return True
n = int(input())
if isprime(n):
print ('Prime')
else:
print ('Not Prime')
Comments
Post a Comment