Created
April 29, 2021 06:12
-
-
Save naveen521kk/0a77fb1d0dde15f707b1c24081b232d1 to your computer and use it in GitHub Desktop.
Check whether a number is prime or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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