Skip to content

Instantly share code, notes, and snippets.

@naveen521kk
Created April 29, 2021 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naveen521kk/0a77fb1d0dde15f707b1c24081b232d1 to your computer and use it in GitHub Desktop.
Save naveen521kk/0a77fb1d0dde15f707b1c24081b232d1 to your computer and use it in GitHub Desktop.
Check whether a number is prime or not
import math
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
sqrt_n = int(math.floor(math.sqrt(n)))
for i in range(3, sqrt_n + 1, 2):
if n % i == 0:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment