Skip to content

Instantly share code, notes, and snippets.

@KarthikMAM
Last active April 18, 2016 17:33
Show Gist options
  • Save KarthikMAM/79d431a13fd36423630b016e7d1734f2 to your computer and use it in GitHub Desktop.
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 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