Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created December 5, 2013 14:07
Show Gist options
  • Save cocodrips/7805665 to your computer and use it in GitHub Desktop.
Save cocodrips/7805665 to your computer and use it in GitHub Desktop.
import math
def primetable(max):
sq = math.sqrt(max)
table = []
t = range(0, max+1)
t[0] = 0
t[1] = 0
p = 2
while p <= sq:
if t[p] != 0:
j = p + p
while j <= max:
t[j] = 0
j += p
p += 1
for p in t:
if p != 0:
table.append(p)
return table
if __name__ == '__main__':
print primetable(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment