Last active
June 14, 2018 13:55
-
-
Save ttowncompiled/4eeeb152b8c13f1cc4d704e1b20b8e32 to your computer and use it in GitHub Desktop.
Generates the first N primes starting with 2. 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 PrimesGen( N: int ) -> List[int]: | |
""" Generates the first N primes starting with 2. """ | |
P: List[int] = [] | |
i: int = 2 | |
while len(P) < N: | |
is_prime: boolean = True | |
for p in P: | |
if i % p == 0: | |
is_prime = False | |
break | |
if is_prime: | |
P.append(i) | |
i += 1 | |
return P |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment