Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: OT: Finding Factor Closest To Square Root

by kvale (Monsignor)
on Feb 20, 2005 at 07:02 UTC ( #432844=note: print w/ replies, xml ) Need Help??


in reply to Re^3: OT: Finding Factor Closest To Square Root
in thread OT: Finding Factor Closest To Square Root

I think the method I sketched does not do what you think :-)

Lets take your example. The square root is 234.277. The largest prime factor is 19. The largest remaining factor is 19, but 19*19 > 234.77, so we try the next largest factor, which is 2. 19*2 <= 234.77, so we keep it. The next largest is 2, and 19*2*2 <= 234.77, so we keep it. The next largest (and final) factor is 2, and 19*2*2*2 = 152 < 234.77, so we stop there. 152 is our best attempt for factor closest to but <= sqrt(54872).

A little thought shows that the greedy method from above will give 54872/152 = 361. If one uses a linear distance, then 152 is the closest factor by the grredy heuristic.

-Mark


Comment on Re^4: OT: Finding Factor Closest To Square Root

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2015-07-07 05:10 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