uses console

================
class BlumPrimes
================
'
int nn 'array elements
sys p 'array buffer address
'
method constructor(int n)
=========================
'generate primes
int i,j,k,t
t=n*2
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
'filter for Blum primes
j=0
for i=1 to t
  k=q[i] 'clipped to 32bits
  if (k and 3) = 3 'quick modulo 4
    j++
    q[j]=q[i]
    if j>=nn
      exit for
    endif
  endif
next
nn=j
'print i cr
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 'BlumPrimes
'
'TEST
=====
new BlumPrimes BP(1000)
int i
for i=1 to BP.nn
  print i tab BP.get(i) cr
next
del BP
wait

