2009-01-18, 05:37 PM
Stereo Wrote:Something I thought about later... sqrt is not cheap (iirc it uses Newton's method to approximate?).
primesList.get(i) <= Math.sqrt(n)
Use
primeslist.get(i)**2 <= n
Huh... not sure why I didn't think about this earlier. The sqrt method uses an iterative equation, that's for sure. One such method: sqrt(2) = 1 + 1/(2 + 1/(2 + 1/(2 + ... ))) = 1.414213...
The total operation time was reduced about 20%. Not bad.

