Skip to content

Instantly share code, notes, and snippets.

@andersonberg
Created November 26, 2014 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonberg/8c2d5b2f3a5eb0b5b64f to your computer and use it in GitHub Desktop.
Save andersonberg/8c2d5b2f3a5eb0b5b64f to your computer and use it in GitHub Desktop.
def primes(int kmax):
cdef int n, k, i
cdef int p[1000]
result = []
if kmax > 1000:
kmax = 1000
k = 0
n = 2
while k < kmax:
i = 0
while i < k and n % p[i] != 0:
i = i + 1
if i == k:
p[k] = n
k = k + 1
result.append(n)
n = n + 1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment