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
Depends on what language you use. Shouldn't it equal to Math.pow(n, 0.5), which uses logaritms?
edit: Implementation-dependent:
![[Image: sqrtms2.png]](http://img530.imageshack.us/img530/9719/sqrtms2.png)
Anyway, I save the value instead of recalculating it. e.g:
sqrt = (int) Math.sqrt(n)
for (i = 5; i < sqrt; i += 6)
instead of:
for (i = 5; i < Math.sqrt(n); i += 6)


![[Image: loopforji9.png]](http://img93.imageshack.us/img93/2480/loopforji9.png)