Skip to content

Instantly share code, notes, and snippets.

@tylerkerr
Last active June 18, 2017 19:35
Show Gist options
  • Save tylerkerr/0cb923c5301948e357d64c27bbe8d1d8 to your computer and use it in GitHub Desktop.
Save tylerkerr/0cb923c5301948e357d64c27bbe8d1d8 to your computer and use it in GitHub Desktop.
#!/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
print(count)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment