uses console

============
class Primes
============
'
int nn 'array elements
sys p 'array buffer address
'
method constructor(int n)
=========================
'generate primes
int i,j,k,t
t=n
redim quad q(t+1)
quad r
quad m=1
indexbase 0
nn=n
i=0
while i<t
  k=1
  for j=2 to i-1
    r=mod(m,q[j])
    if r=0
      k=0
      exit for
    endif
  next
  if k
    i++
    q[i]=m
  endif
  m++
wend
nn=n
p=@q
end method
'
method get(int i) as quad
if i<1 or i>nn
  exit method
endif
quad q at (i*8+p)
return q
end method
'
end class 'Primes
'
'TEST
=====
new Primes P(1000)
int i
for i=1 to P.nn
  print i tab P.get(i) cr
next
del P
wait

