in reply to Prime Number Finder
There's also Math::Pari which can do this sort of calculation extremely fast and with huge numbers:
use strict; use Math::Pari qw(:int PARI nextprime); print "Find primes from: "; chomp(my $o = <>); print "to: "; chomp(my $e = <>); $o = PARI $o; $e = PARI $e; if ($o > $e) { ($o,$e) = ($e,$o); } my $p = nextprime($o); while ($p <= $e) { print "$p is prime\n"; $p = nextprime($p + 1); }
Update: Fixed the code so that numbers not representable as integers can be converted to PARI objects.
|
---|
In Section
Cool Uses for Perl