Created
April 7, 2014 06:36
-
-
Save sapamja/10015698 to your computer and use it in GitHub Desktop.
Seive_Prime in python
This file contains hidden or 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
#!/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