cdef extern from "stdlib.h": ctypedef int size_t void *malloc(size_t size) void free(void *ptr) def cprimes(int kmax): cdef int n, k, i cdef int *p p = malloc(kmax * sizeof(int)) result = [] 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 free(p) p = NULL return result