File: primes.pyx

package info (click to toggle)
pyrex 0.9.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,140 kB
  • ctags: 2,220
  • sloc: python: 10,912; ansic: 3,111; makefile: 103; lisp: 12
file content (18 lines) | stat: -rw-r--r-- 272 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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