1// The Great Computer Language Shootout 2// http://shootout.alioth.debian.org 3// 4// Contributed by Ian Osgood 5 6function pad(n,width) { 7 var s = n.toString(); 8 while (s.length < width) s = ' ' + s; 9 return s; 10} 11 12function primes(isPrime, n) { 13 var i, count = 0, m = 10000<<n, size = m+31>>5; 14 15 for (i=0; i<size; i++) isPrime[i] = 0xffffffff; 16 17 for (i=2; i<m; i++) 18 if (isPrime[i>>5] & 1<<(i&31)) { 19 for (var j=i+i; j<m; j+=i) 20 isPrime[j>>5] &= ~(1<<(j&31)); 21 count++; 22 } 23} 24 25function sieve() { 26 for (var i = 4; i <= 4; i++) { 27 var isPrime = new Array((10000<<i)+31>>5); 28 primes(isPrime, i); 29 } 30} 31 32sieve(); 33