Keep It Simple, Stupid 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2018-06-19 13:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (114 votes). Check out past polls.

Notices?