Created
November 26, 2014 16:59
-
-
Save andersonberg/8c2d5b2f3a5eb0b5b64f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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