Skip to content

Instantly share code, notes, and snippets.

@sota1235
Created March 30, 2014 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sota1235/9869824 to your computer and use it in GitHub Desktop.
Save sota1235/9869824 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
def sieve(n):
nums = [i+1 for i in range(2, n, 2)]
ans = [2]
while len(nums) != 0:
for i in range(nums[0]*2, nums[-1]+1, nums[0]):
if i in nums: nums.remove(i)
ans.append(nums.pop(0))
return ans
print sieve(10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment