Skip to content

Instantly share code, notes, and snippets.

@adamori
Created March 21, 2023 15:07
Show Gist options
  • Save adamori/03176a3019332cdc76a166c5ca00c40e to your computer and use it in GitHub Desktop.
Save adamori/03176a3019332cdc76a166c5ca00c40e to your computer and use it in GitHub Desktop.
import math
def is_simple_number(n):
if n < 2:
return False
elif n == 2:
return True
elif n % 2 == 0:
return False
else:
for i in range(3, int(math.sqrt(n))+1, 2):
if n % i == 0:
return False
return True
print(is_simple_number(1)) # False
print(is_simple_number(0)) # False
print(is_simple_number(2)) # True
print(is_simple_number(13)) # True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment