Skip to content

Instantly share code, notes, and snippets.

@sapamja
Created April 7, 2014 06:36
Show Gist options
  • Save sapamja/10015698 to your computer and use it in GitHub Desktop.
Save sapamja/10015698 to your computer and use it in GitHub Desktop.
Seive_Prime in python
#!/usr/bin/python
# inserting 1 for every prime and 0 of non prime within a given range
def prime_list(n):
pr = [-1] * n
ind = 2
pr[0] = pr[1] = 0
pr[2] = 1
while ind <= n:
for i in range(ind, n, ind):
if i == ind:
pr[i] = 1
else:
pr[i] = 0
ind +=1
try:
while pr[ind] != -1 and ind < n:
ind += 1
except:
pass
print pr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment