Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Prime Number Finder

by tall_man (Parson)
on Mar 07, 2005 at 23:00 UTC ( #437338=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: Prime Number Finder
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://437338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2015-07-07 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls