Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by kvale (Monsignor)
on Feb 20, 2005 at 07:02 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://432844]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2024-04-25 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found