Last active
June 14, 2018 13:54
-
-
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).
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
# 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