Eratosthenes Sieve, is used to quickly find Prime numbers. He wrote it 250 bc.
For numbers less than 10,000,000 is purported to be faster to generate the numbers rather than find them in a file.

sub Eratosthenes_Sieve($) { for(@a=(1)x($_[0]+1),$p=2;$p**2<$_[0];){for($j=2*$p;$j<$_ [0];$j+=$p){$a[$j]=0}for($a[++$p]){}}grep{$a[$_]}(2..$#a) }

I've made it tricky to read, and concise, I just loved the concept.
I'm not saying give up using Pari ;), it just amazed me that this equation was found two and a quarter millenia ago, ain't Maths cool.
Don't worry your RSA keys are safe, 32 Bit encryption will render:
four thousand, two hundred and ninetyfour million nine hundred and sixtyseven thousand two hundred and ninetysix digits ;)

Update: It's been done before :(, needless to say far better too, especially meowchow..

--

Brother Frankus.

¤

Replies are listed 'Best First'.
Re: Eratosthenes Sieve
by IraTarball (Monk) on Oct 22, 2001 at 20:54 UTC
    Not to be a pain in the ass, but I noticed yours always gives the seed number as the last element of the list. I thought the method only gave the seed number if it was prime. I took a look at the link you have above and it seems to confirm this. I made your <'s into <='s and it works like The Others.

    sub Eratosthenes_Sieve($){ for(@a=(1)x($_[0]+1),$p=2; $p**2<=$_[0];){for($j=2*$p ;$j<=$_[0];$j+=$p){$a[$j]= 0}for($a[++$p]){}}grep {$a [$_]}(2..$#a)}

    Ira,

    "So... What do all these little arrows mean?"
    ~unknown