Skip to content

Instantly share code, notes, and snippets.

@TheRealMentor
Created June 28, 2019 16:19
Show Gist options
  • Save TheRealMentor/2c5c880739faacaf4d84bce37da3736f to your computer and use it in GitHub Desktop.
Save TheRealMentor/2c5c880739faacaf4d84bce37da3736f to your computer and use it in GitHub Desktop.
'''
@author: TheRealMentor
@date: 28/06/2019
'''
import math
def isPrime(A):
#Check if A = 1
if A == 1:
return False
#Check if A = 2 or 3
if A == 2 or A == 3:
return True
#Check if A % i == 0 upto sqrt(n). This is trial division method.
for i in range(2, int(math.sqrt(A))+1):
if i < A and A % i == 0:
return False
return True
print(isPrime(7))
print(isPrime(19))
print(isPrime(21))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment