javascript - Oscillate counter increment? -


i want reduce computing load in test primes. loop tests odds, so:

for (k=3; k<=end; k+=2) { 

i read every prime other 2 , 3 function of k= 6 +/- 1 though. testing 2/3rds of odds can reduce computing load 33%. way can think oscillate counter increment 2, 4, 2, 4 each iteration, example testing 5, 7, 11, 13, etc.

is there way tell loop this? there way i'm not considering?

p.s. i'm aware of sieve method of testing

use while loop, instead:

k = 3; odd = false; while( k<=end ) {     k += odd ? 2 : 4;     odd = !odd; } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -