Created
June 28, 2019 16:19
-
-
Save TheRealMentor/2c5c880739faacaf4d84bce37da3736f to your computer and use it in GitHub Desktop.
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
''' | |
@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