Generating prime numbers

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Generating prime numbers

Cheema, Jaspal (MCYS)
Generating prime numbers

Hi all

I’m looking for SPSS code to generate ‘Prime Numbers’ between a given range (a lower bound and an upper bound to be input by the user).

The output is to be saved in an SPSS file as it is generated (to be saved in the C: drive).

I’d really appreciate this as it is beyond my programming skills.

Thanks a lot.

Jaspal Cheema

Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

David Marso
Administrator
SPSS syntax is really not designed for such an exercise.
If one were a unrelenting masochist it could likely be done but I'm not going to bother.
There is code in other languages scattered all over the net in different languages.
Do a little googling and you can probably find a python implementation which can be readily called within SPSS.

Cheema, Jaspal (MCYS) wrote
Hi all
I'm looking for SPSS code to generate 'Prime Numbers' between a given
range (a lower bound and an upper bound to be input by the user).
The output is to be saved in an SPSS file as it is generated (to be
saved in the C: drive).
I'd really appreciate this as it is beyond my programming skills.
Thanks a lot.
Jaspal Cheema
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

David Marso
Administrator
Ah, to hell with it ;-)
Here is a MATRIX program implementing http://umumble.com/blogs/algorithm/334/
If you are working with *large* numbers then this is probably not the way to go.
---

SET MXLOOPS 250000.
MATRIX.
COMPUTE P=MAKE(250000,1,1).
COMPUTE TOP=NROW(P).
COMPUTE PRIMES={1}.
LOOP #=2 TO TOP.
+  DO IF P(#) NE 0.
+    COMPUTE PRIMES={PRIMES;#}.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE P(##,1)=0.
+    END LOOP.
+  END IF.
END LOOP.
**PRINT PRIMES.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIME.
END MATRIX.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

Bruce Weaver
Administrator
LOL...I had a feeling you'd not be able to resist taking a crack at it!  Nicely done.  ;-)


David Marso wrote
Ah, to hell with it ;-)
Here is a MATRIX program implementing http://umumble.com/blogs/algorithm/334/
If you are working with *large* numbers then this is probably not the way to go.
---

SET MXLOOPS 250000.
MATRIX.
COMPUTE P=MAKE(250000,1,1).
COMPUTE TOP=NROW(P).
COMPUTE PRIMES={1}.
LOOP #=2 TO TOP.
+  DO IF P(#) NE 0.
+    COMPUTE PRIMES={PRIMES;#}.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE P(##,1)=0.
+    END LOOP.
+  END IF.
END LOOP.
**PRINT PRIMES.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIME.
END MATRIX.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

David Marso
Administrator
Bruce Weaver wrote
LOL...I had a feeling you'd not be able to resist taking a crack at it!  Nicely done.  ;-)
I got sucked into another one eh?
Not to let my masochism go easy I tracked down the following and really went down the rabbit hole ;-)))
Hexile Sieve Analysis of Prime and Composite Integers.  http://arxiv.org/pdf/1202.5948v1.pdf

*****NOTICE col 2,4 and 6 are all *EVEN* col 3 is a multiple of 3.
Reserve 2,3,5 as prime
So we build a k * 6 matrix using that idea (col 2,4,6,3 all zero).
RESHAPE to k2*5 and clobber row 5 to nuke the 5 factor then VECTOR the whole thing
 and run the loop as previous.

   1   2  3   4   5   6
   7   8  9 10 11 12
 13 14 15 16 17 18
 19 20 21 22 23 24
 25 26 27 28 29 30
 31 32 33 34 35 36
 37 38 39 40 41 42
 43 44 45 46 47 48
 49 50 51 52 53 54
 55 56 57 58 59 60
...
...
...

SET MXLOOPS=300000.
MATRIX .
COMPUTE TOP=300000.
COMPUTE PRIMES={2;3;5}.
COMPUTE X=MAKE(50000,6,1).
COMPUTE X(:,2:4)=MAKE(50000,3,0).
COMPUTE X(:,6)=MAKE(50000,1,0).
COMPUTE X=RESHAPE(X,60000,5).
COMPUTE X(:,5)=MAKE(60000,1,0).
COMPUTE X=RESHAPE(X,300000,1).
LOOP #=7 TO TOP.
+  DO IF X(#) NE 0.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE X(##,1)=0.
+    END LOOP.
+    COMPUTE PRIMES={PRIMES;#}.
+  END IF.
END LOOP.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIMENEW.
END MATRIX.



David Marso wrote
Ah, to hell with it ;-)
Here is a MATRIX program implementing http://umumble.com/blogs/algorithm/334/
If you are working with *large* numbers then this is probably not the way to go.
---

SET MXLOOPS 250000.
MATRIX.
COMPUTE P=MAKE(250000,1,1).
COMPUTE TOP=NROW(P).
COMPUTE PRIMES={1}.
LOOP #=2 TO TOP.
+  DO IF P(#) NE 0.
+    COMPUTE PRIMES={PRIMES;#}.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE P(##,1)=0.
+    END LOOP.
+  END IF.
END LOOP.
**PRINT PRIMES.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIME.
END MATRIX.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Automatic reply: Generating prime numbers

Jenny Bartashnik

Hi,

 

Thank you for contacting Reputation Institute’s MSG.

 

The office is closed for Memorial Day Monday May 28.  I will respond to your email when we're back on Tuesday May 29.

 

Best,

Jenny

Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

Len Vir
In reply to this post by Cheema, Jaspal (MCYS)
With SPSS 20 and Essentials for R
The prime function is from:
http://www.r-bloggers.com/prime-number-in-r-language-cloudstat/



BEGIN PROGRAM R.
prime = function(n)
{
   n = as.integer(n)
   if(n > 1e8) stop("n too large")
   primes = rep(TRUE, n)
   primes[1] = FALSE
   last.prime = 2L
   fsqr = floor(sqrt(n))
   while (last.prime <= fsqr)
   {
      primes[seq.int(2L*last.prime, n, last.prime)] = FALSE
      sel = which(primes[(last.prime+1):(fsqr+1)])
      if(any(sel)){
        last.prime = last.prime + min(sel)
      }else last.prime = fsqr+1
   }
   which(primes)
}

#   To get all primes less than 100

prime(100)

#  To get primes from the fifth prime to the tenth prime

primes2 <- prime(100)
primes2[5:10]

#  To get the fifth, the seventh and the tenth primes

primes2[c(5,7,10)]

#  To get all primes less than 100 but the fifth and the tenth primes

primes2[-c(5,10)]

end program.


Len


On Fri, May 25, 2012 at 2:13 PM, Cheema, Jaspal (MCYS)
<[hidden email]> wrote:

> Hi all
>
> I’m looking for SPSS code to generate ‘Prime Numbers’ between a given range
> (a lower bound and an upper bound to be input by the user).
>
> The output is to be saved in an SPSS file as it is generated (to be saved in
> the C: drive).
>
> I’d really appreciate this as it is beyond my programming skills.
>
> Thanks a lot.
>
> Jaspal Cheema

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

Len Vir
In reply to this post by Cheema, Jaspal (MCYS)
The saving part was missing in my previous message.


BEGIN PROGRAM R.
prime = function(n)
{
   n = as.integer(n)
   if(n > 1e8) stop("n too large")
   primes = rep(TRUE, n)
   primes[1] = FALSE
   last.prime = 2L
   fsqr = floor(sqrt(n))
   while (last.prime <= fsqr)
   {
      primes[seq.int(2L*last.prime, n, last.prime)] = FALSE
      sel = which(primes[(last.prime+1):(fsqr+1)])
      if(any(sel)){
        last.prime = last.prime + min(sel)
      }else last.prime = fsqr+1
   }
   which(primes)
}

#   To get all primes less than 100

prime(100)

#  To get primes from the fifth prime to the tenth prime

primes2 <- prime(100)
primes2[5:10]

#  To get the fifth, the seventh and the tenth primes
primes2[c(5,7,10)]

#  To get all primes less than 100 but the fifth and the tenth primes

primes2[-c(5,10)]

#   The following code will save the primes to the C: drive in a text file,
#   together with a code file to read the text file from SPSS

p2 <- primes2[5:10]

options(stringsAsFactors = FALSE)

mydata <- data.frame(p2)

library(foreign)
write.foreign(mydata, "c:/mydata.txt", "c:/mydata.sps",   package="SPSS")


end program.


Len



On Fri, May 25, 2012 at 2:13 PM, Cheema, Jaspal (MCYS)
<[hidden email]> wrote:

> Hi all
>
> I’m looking for SPSS code to generate ‘Prime Numbers’ between a given range
> (a lower bound and an upper bound to be input by the user).
>
> The output is to be saved in an SPSS file as it is generated (to be saved in
> the C: drive).
>
> I’d really appreciate this as it is beyond my programming skills.
>
> Thanks a lot.
>
> Jaspal Cheema

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

David Marso
Administrator
In reply to this post by David Marso
Some hopefully obvious optimizations ;-))
Trick question:  What are they?
-----------------
DEFINE PRIMES (N !TOKENS(1)).
PRESERVE.
SET MXLOOPS !N.
MATRIX.
+  COMPUTE X=MAKE(!N,1,1).
+  COMPUTE TOP=NROW(X).
+  COMPUTE TOP2=TRUNC(SQRT(TOP)).
+  COMPUTE #PRIMES=MAKE(TRUNC(!N/10),1,0).
+  COMPUTE #PRIMES(1)=2.
+  COMPUTE #NPrime=2.
+  LOOP #=3 TO TOP BY 2.
+    DO IF (X(#) EQ 1).
+      DO IF (# LT TOP2).
+        LOOP ##=2*# TO TOP BY #.
+          COMPUTE X(##)=0.
+        END LOOP.
+      END IF.
+      COMPUTE #PRIMES(#NPrime)=#.
+      COMPUTE #NPrime=#NPrime+1.
+      DO IF #NPrime GT NROW(#PRIMES).
+        COMPUTE #PRIMES={#PRIMES;MAKE(TRUNC(NROW(#PRIMES)/4),1,0)}.
+        PRINT #Nprime.
+      END IF.
+    END IF.
+  END LOOP.
SAVE #PRIMES/OUTFILE * / VARIABLES=PRIMEOLD.
END MATRIX.
RESTORE.
SELECT IF PRIMEOLD > 0.
EXE.
!ENDDEFINE.
PRIMES N=500000.
David Marso wrote
Bruce Weaver wrote
LOL...I had a feeling you'd not be able to resist taking a crack at it!  Nicely done.  ;-)
I got sucked into another one eh?
Not to let my masochism go easy I tracked down the following and really went down the rabbit hole ;-)))
Hexile Sieve Analysis of Prime and Composite Integers.  http://arxiv.org/pdf/1202.5948v1.pdf

*****NOTICE col 2,4 and 6 are all *EVEN* col 3 is a multiple of 3.
Reserve 2,3,5 as prime
So we build a k * 6 matrix using that idea (col 2,4,6,3 all zero).
RESHAPE to k2*5 and clobber row 5 to nuke the 5 factor then VECTOR the whole thing
 and run the loop as previous.

   1   2  3   4   5   6
   7   8  9 10 11 12
 13 14 15 16 17 18
 19 20 21 22 23 24
 25 26 27 28 29 30
 31 32 33 34 35 36
 37 38 39 40 41 42
 43 44 45 46 47 48
 49 50 51 52 53 54
 55 56 57 58 59 60
...
...
...

SET MXLOOPS=300000.
MATRIX .
COMPUTE TOP=300000.
COMPUTE PRIMES={2;3;5}.
COMPUTE X=MAKE(50000,6,1).
COMPUTE X(:,2:4)=MAKE(50000,3,0).
COMPUTE X(:,6)=MAKE(50000,1,0).
COMPUTE X=RESHAPE(X,60000,5).
COMPUTE X(:,5)=MAKE(60000,1,0).
COMPUTE X=RESHAPE(X,300000,1).
LOOP #=7 TO TOP.
+  DO IF X(#) NE 0.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE X(##,1)=0.
+    END LOOP.
+    COMPUTE PRIMES={PRIMES;#}.
+  END IF.
END LOOP.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIMENEW.
END MATRIX.



David Marso wrote
Ah, to hell with it ;-)
Here is a MATRIX program implementing http://umumble.com/blogs/algorithm/334/
If you are working with *large* numbers then this is probably not the way to go.
---

SET MXLOOPS 250000.
MATRIX.
COMPUTE P=MAKE(250000,1,1).
COMPUTE TOP=NROW(P).
COMPUTE PRIMES={1}.
LOOP #=2 TO TOP.
+  DO IF P(#) NE 0.
+    COMPUTE PRIMES={PRIMES;#}.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE P(##,1)=0.
+    END LOOP.
+  END IF.
END LOOP.
**PRINT PRIMES.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIME.
END MATRIX.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

Bruce Weaver
Administrator
You appear to be well primed for Memorial Day, David.  :-|


David Marso wrote
Some hopefully obvious optimizations ;-))
Trick question:  What are they?
-----------------
DEFINE PRIMES (N !TOKENS(1)).
PRESERVE.
SET MXLOOPS !N.
MATRIX.
+  COMPUTE X=MAKE(!N,1,1).
+  COMPUTE TOP=NROW(X).
+  COMPUTE TOP2=TRUNC(SQRT(TOP)).
+  COMPUTE #PRIMES=MAKE(TRUNC(!N/10),1,0).
+  COMPUTE #PRIMES(1)=2.
+  COMPUTE #NPrime=2.
+  LOOP #=3 TO TOP BY 2.
+    DO IF (X(#) EQ 1).
+      DO IF (# LT TOP2).
+        LOOP ##=2*# TO TOP BY #.
+          COMPUTE X(##)=0.
+        END LOOP.
+      END IF.
+      COMPUTE #PRIMES(#NPrime)=#.
+      COMPUTE #NPrime=#NPrime+1.
+      DO IF #NPrime GT NROW(#PRIMES).
+        COMPUTE #PRIMES={#PRIMES;MAKE(TRUNC(NROW(#PRIMES)/4),1,0)}.
+        PRINT #Nprime.
+      END IF.
+    END IF.
+  END LOOP.
SAVE #PRIMES/OUTFILE * / VARIABLES=PRIMEOLD.
END MATRIX.
RESTORE.
SELECT IF PRIMEOLD > 0.
EXE.
!ENDDEFINE.
PRIMES N=500000.
David Marso wrote
Bruce Weaver wrote
LOL...I had a feeling you'd not be able to resist taking a crack at it!  Nicely done.  ;-)
I got sucked into another one eh?
Not to let my masochism go easy I tracked down the following and really went down the rabbit hole ;-)))
Hexile Sieve Analysis of Prime and Composite Integers.  http://arxiv.org/pdf/1202.5948v1.pdf

*****NOTICE col 2,4 and 6 are all *EVEN* col 3 is a multiple of 3.
Reserve 2,3,5 as prime
So we build a k * 6 matrix using that idea (col 2,4,6,3 all zero).
RESHAPE to k2*5 and clobber row 5 to nuke the 5 factor then VECTOR the whole thing
 and run the loop as previous.

   1   2  3   4   5   6
   7   8  9 10 11 12
 13 14 15 16 17 18
 19 20 21 22 23 24
 25 26 27 28 29 30
 31 32 33 34 35 36
 37 38 39 40 41 42
 43 44 45 46 47 48
 49 50 51 52 53 54
 55 56 57 58 59 60
...
...
...

SET MXLOOPS=300000.
MATRIX .
COMPUTE TOP=300000.
COMPUTE PRIMES={2;3;5}.
COMPUTE X=MAKE(50000,6,1).
COMPUTE X(:,2:4)=MAKE(50000,3,0).
COMPUTE X(:,6)=MAKE(50000,1,0).
COMPUTE X=RESHAPE(X,60000,5).
COMPUTE X(:,5)=MAKE(60000,1,0).
COMPUTE X=RESHAPE(X,300000,1).
LOOP #=7 TO TOP.
+  DO IF X(#) NE 0.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE X(##,1)=0.
+    END LOOP.
+    COMPUTE PRIMES={PRIMES;#}.
+  END IF.
END LOOP.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIMENEW.
END MATRIX.



David Marso wrote
Ah, to hell with it ;-)
Here is a MATRIX program implementing http://umumble.com/blogs/algorithm/334/
If you are working with *large* numbers then this is probably not the way to go.
---

SET MXLOOPS 250000.
MATRIX.
COMPUTE P=MAKE(250000,1,1).
COMPUTE TOP=NROW(P).
COMPUTE PRIMES={1}.
LOOP #=2 TO TOP.
+  DO IF P(#) NE 0.
+    COMPUTE PRIMES={PRIMES;#}.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE P(##,1)=0.
+    END LOOP.
+  END IF.
END LOOP.
**PRINT PRIMES.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIME.
END MATRIX.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Generating prime numbers

David Marso
Administrator
Also introduced a teensy bug.  Can you find it?
--
Bruce Weaver wrote
You appear to be well primed for Memorial Day, David.  :-|


David Marso wrote
Some hopefully obvious optimizations ;-))
Trick question:  What are they?
-----------------
DEFINE PRIMES (N !TOKENS(1)).
PRESERVE.
SET MXLOOPS !N.
MATRIX.
+  COMPUTE X=MAKE(!N,1,1).
+  COMPUTE TOP=NROW(X).
+  COMPUTE TOP2=TRUNC(SQRT(TOP)).
+  COMPUTE #PRIMES=MAKE(TRUNC(!N/10),1,0).
+  COMPUTE #PRIMES(1)=2.
+  COMPUTE #NPrime=2.
+  LOOP #=3 TO TOP BY 2.
+    DO IF (X(#) EQ 1).
+      DO IF (# LT TOP2).
+        LOOP ##=2*# TO TOP BY #.
+          COMPUTE X(##)=0.
+        END LOOP.
+      END IF.
+      COMPUTE #PRIMES(#NPrime)=#.
+      COMPUTE #NPrime=#NPrime+1.
+      DO IF #NPrime GT NROW(#PRIMES).
+        COMPUTE #PRIMES={#PRIMES;MAKE(TRUNC(NROW(#PRIMES)/4),1,0)}.
+        PRINT #Nprime.
+      END IF.
+    END IF.
+  END LOOP.
SAVE #PRIMES/OUTFILE * / VARIABLES=PRIMEOLD.
END MATRIX.
RESTORE.
SELECT IF PRIMEOLD > 0.
EXE.
!ENDDEFINE.
PRIMES N=500000.
David Marso wrote
Bruce Weaver wrote
LOL...I had a feeling you'd not be able to resist taking a crack at it!  Nicely done.  ;-)
I got sucked into another one eh?
Not to let my masochism go easy I tracked down the following and really went down the rabbit hole ;-)))
Hexile Sieve Analysis of Prime and Composite Integers.  http://arxiv.org/pdf/1202.5948v1.pdf

*****NOTICE col 2,4 and 6 are all *EVEN* col 3 is a multiple of 3.
Reserve 2,3,5 as prime
So we build a k * 6 matrix using that idea (col 2,4,6,3 all zero).
RESHAPE to k2*5 and clobber row 5 to nuke the 5 factor then VECTOR the whole thing
 and run the loop as previous.

   1   2  3   4   5   6
   7   8  9 10 11 12
 13 14 15 16 17 18
 19 20 21 22 23 24
 25 26 27 28 29 30
 31 32 33 34 35 36
 37 38 39 40 41 42
 43 44 45 46 47 48
 49 50 51 52 53 54
 55 56 57 58 59 60
...
...
...

SET MXLOOPS=300000.
MATRIX .
COMPUTE TOP=300000.
COMPUTE PRIMES={2;3;5}.
COMPUTE X=MAKE(50000,6,1).
COMPUTE X(:,2:4)=MAKE(50000,3,0).
COMPUTE X(:,6)=MAKE(50000,1,0).
COMPUTE X=RESHAPE(X,60000,5).
COMPUTE X(:,5)=MAKE(60000,1,0).
COMPUTE X=RESHAPE(X,300000,1).
LOOP #=7 TO TOP.
+  DO IF X(#) NE 0.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE X(##,1)=0.
+    END LOOP.
+    COMPUTE PRIMES={PRIMES;#}.
+  END IF.
END LOOP.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIMENEW.
END MATRIX.



David Marso wrote
Ah, to hell with it ;-)
Here is a MATRIX program implementing http://umumble.com/blogs/algorithm/334/
If you are working with *large* numbers then this is probably not the way to go.
---

SET MXLOOPS 250000.
MATRIX.
COMPUTE P=MAKE(250000,1,1).
COMPUTE TOP=NROW(P).
COMPUTE PRIMES={1}.
LOOP #=2 TO TOP.
+  DO IF P(#) NE 0.
+    COMPUTE PRIMES={PRIMES;#}.
+    LOOP ##=2*# TO TOP BY #.
+      COMPUTE P(##,1)=0.
+    END LOOP.
+  END IF.
END LOOP.
**PRINT PRIMES.
SAVE PRIMES/OUTFILE * / VARIABLES=PRIME.
END MATRIX.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"