Last active
April 18, 2016 17:33
-
-
Save KarthikMAM/79d431a13fd36423630b016e7d1734f2 to your computer and use it in GitHub Desktop.
Finds the prime numbers faster by checking divisions by prime numbers only
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
#This algorithm will find the prime numbers | |
#faster than conventional methods | |
#by checking only the prime number divisiblity | |
prime = [2] | |
for i in range(2, int(input())): | |
l = int(i ** 0.5) + 1 | |
for j in prime: | |
if j > l: | |
prime.append(i) | |
break | |
elif i % j == 0: | |
break | |
else: | |
prime.append(i) | |
print(prime) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment