-
-
Save tylerkerr/0cb923c5301948e357d64c27bbe8d1d8 to your computer and use it in GitHub Desktop.
This file contains 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/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