Skip to content

Instantly share code, notes, and snippets.

@ttowncompiled
Last active June 14, 2018 13:55
Show Gist options
  • Save ttowncompiled/4eeeb152b8c13f1cc4d704e1b20b8e32 to your computer and use it in GitHub Desktop.
Save ttowncompiled/4eeeb152b8c13f1cc4d704e1b20b8e32 to your computer and use it in GitHub Desktop.
Generates the first N primes starting with 2. complexity: O(N**2).
# 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