primes.pyx 402 Bytes
Newer Older
1 2 3
# cython: language_level=3

print("starting")
Robert Bradshaw's avatar
Robert Bradshaw committed
4

William Stein's avatar
William Stein committed
5
def primes(int kmax):
Robert Bradshaw's avatar
Robert Bradshaw committed
6
    # cdef int n, k, i
William Stein's avatar
William Stein committed
7 8 9 10 11 12 13 14
    cdef int p[1000]
    result = []
    if kmax > 1000:
        kmax = 1000
    k = 0
    n = 2
    while k < kmax:
        i = 0
15 16
        while i < k and n % p[i] != 0:
            i += 1
William Stein's avatar
William Stein committed
17 18
        if i == k:
            p[k] = n
19
            k += 1
William Stein's avatar
William Stein committed
20
            result.append(n)
21
        n += 1
William Stein's avatar
William Stein committed
22
    return result