var blob = use('blob')
var math = use('math/radians')

var i = 0
var j = 0

function eratosthenes (n) {
  var sieve = blob(n, true)
  var sqrtN = whole(math.sqrt(n));

  for (i = 2; i <= sqrtN; i++)
    if (sieve.read_logical(i))
      for (j = i * i; j <= n; j += i)
          sieve.write_bit(j, false);

  return sieve;
}

var sieve = eratosthenes(10000000);
stone(sieve)

var c = 0
for (i = 0; i < length(sieve); i++)
  if (sieve.read_logical(i)) c++

log.console(c)

$stop()
