Skip to content

Instantly share code, notes, and snippets.

Last active June 18, 2017 19:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#!/usr/bin/env python3
import sys
def main():
start, end = 0, int(sys.argv[1])
primelist = [True] * (end+1) # populate array with Trues from 0
primelist[0], primelist[1] = False, False # 0 and 1 are not primes
for i in range(2, int(end ** 0.5)+1): # the sieve
if primelist[i]:
j = i ** 2
while j < end+1:
primelist[j] = False
j += i
count = 0
for (n, prime) in enumerate(primelist): # print any numbers marked as True
if prime:
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment