laziness, impatience, and hubris 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??

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

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 romping around the Monastery: (3)
As of 2020-10-20 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favourite web site is:

Results (208 votes). Check out past polls.

Notices?