in reply to Re^2: OT: Finding Factor Closest To Square Root
in thread OT: Finding Factor Closest To Square Root
Certainly you don't have to go beyond 2*sqrt(N) on the ++ side
The high side search would always have terminated there or earlier anyway as it stopped as soon as the difference between it and the root was greater than that between lo and root. Lo can't go below 1, so hi would never go above root*2-1. But skipping the hi search is much better.
Another optimisation possible if N is odd, is to step back by 2 each time.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: OT: Finding Factor Closest To Square Root
by QM (Parson) on Feb 20, 2005 at 07:39 UTC | |
by BrowserUk (Patriarch) on Feb 20, 2005 at 15:26 UTC | |
by hv (Prior) on Feb 21, 2005 at 10:15 UTC | |
by BrowserUk (Patriarch) on Feb 21, 2005 at 17:56 UTC | |
by tall_man (Parson) on Feb 22, 2005 at 17:36 UTC | |
|