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

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

by QM (Parson)
on Feb 20, 2005 at 05:33 UTC ( #432837=note: print w/replies, xml ) Need Help??

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

To fill a box of size log(N)/2, put the largest factor into the box. Then put the next largest factor that still fits in the box and insert it. Keep doing this until no more factors fit.

The above will get you the largest factor <= sqrt(N). To get the smallest factor >= sqrt(N), put all the factors in a box, and take them out again largest to smallest, until no more can be taken out. Finally, comapre the two answers to find the closest.

I don't think that does what you think. For example, 2**3 * 19**3 = 54872, and the square root is 234.277....

Your method gives 19 as the largest less than the square root, and 2**3 * 19**2 = 2888 as the smallest greater than the square root. Notice that 19*2888 = 54872.

A better result is 2**3 * 19 = 152 (because 19**2 = 361).

Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^4: OT: Finding Factor Closest To Square Root
by kvale (Monsignor) on Feb 20, 2005 at 07:02 UTC
    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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://432837]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-04-29 13:30 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.