Skip to content

Instantly share code, notes, and snippets.

@ttowncompiled
Last active June 14, 2018 13:54
Show Gist options
  • Save ttowncompiled/fb5688f75aea7200208d251dbc46cf4b to your computer and use it in GitHub Desktop.
Save ttowncompiled/fb5688f75aea7200208d251dbc46cf4b to your computer and use it in GitHub Desktop.
Generates a complete list of primes P s.t. for all p in P, p < N. complexity: O(N**2).
# python 3.6.5
# from typing import List
def Primes( N: int ) -> List[int]:
""" Generates a complete list of primes P s.t. for all p in P, p < N. """
P: List[int] = []
A: List[int] = [ n+1 for n in range( N ) ]
for n in range( 1, N+1 ):
if A[n-1] == 1:
continue
P.append( A[n-1] )
for m in range( n, N+1, n ):
A[m-1] = 1
return P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment