Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Stupidest Prime Number detector ever!!

by choroba (Cardinal)
on Jun 23, 2021 at 18:56 UTC ( [id://11134210]=note: print w/replies, xml ) Need Help??


in reply to Stupidest Prime Number detector ever!!

If a candidate is not a prime, it must have a divisor that's less than the square root of the candidate (proof left as an exercise to the reader).
for my $each_num (2 .. sqrt $prime_candidate) { if ($prime_candidate % $each_num == 0) { say ...

For another speed-up, skip all the even numbers but 2.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found