schnellst methode primzahlen zu sieben ist das sieb des eresthotenes:
use strict;
my $max = 100; # obergrenze bis wohin wir berechnen
my @sieb=(0..$max); # sieb des erestothenes
for my $i (2..($max/2)){
next unless $sieb[$i];
$sieb[$i*$_] = 0 for 2..int $max/$i;
}
# ausgabe
for my $i (2..$max) { print "$sieb[$i] " if $sieb[$i] }
bei sher grossen zahlen vielleicht besser
use strict;
my $max = 100; # obergrenze bis wohin wir berechnen
my @sieb = $max; # sieb des erestothenes
for my $i (2..($max/2)){
next if $sieb[$i];
$sieb[$i*$_] = 1 for 2..int $max/$i;
}
# ausgabe
for my $i (2..$max) { print "$i " unless $sieb[$i] }
\n\n
<!--EDIT|lichtkind|1147696965-->