Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: YAPNC: Yet another prime number checker?

by nefertari (Chaplain)
on Oct 09, 2002 at 07:32 UTC ( #203853=note: print w/replies, xml ) Need Help??


in reply to Re: YAPNC: Yet another prime number checker?
in thread YAPNC: Yet another prime number checker?

You can stop at sqrt($input).

Example:
The divisors of 100 are:
1, 2, 4, 5, 10, 20, 25, 50, 100. They come in pairs as follows:

1*100 = 100 2*50 = 100 4* 25= 100 5*20 = 100 10*10 =100 20*5= 100
and so on. So at 10 which is sqrt(10) you are at the point where the second factor is smaller than the first and you have already tested for this pair.

Replies are listed 'Best First'.
Re^3: YAPNC: Yet another prime number checker?
by JaWi (Hermit) on Oct 09, 2002 at 07:39 UTC
    nefertari++: You're absolutely and totally right! Well, even less cycles to perform :-)

    -- JaWi

    "A chicken is an egg's way of producing more eggs."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-01-24 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?