function Filter(number, filter) {
    this.number = number;
    this.filter = filter;
}
Filter.prototype.accept = function(n) {
  var filter = this;
  for (;;) {
      if (n % filter.number === 0) {
          return false;
      }
      filter = filter.filter;
      if (filter === null) {
          break;
      }
  }
  return true;
};

function Primes(natural) {
    this.natural = natural;
    this.at = 0;
    this.filter = null;
}
Primes.prototype.next = function() {
    for (;;) {
        var n = this.natural[this.at++];
        if (this.filter === null || this.filter.accept(n)) {
            this.filter = new Filter(n, this.filter);
            return n;
        }
    }
};

function measure(prntCnt, upto) {
    var natural = Interop.import('Natural');
    var primes = new Primes(Interop.execute(natural));
    
    var log = typeof console !== 'undefined' ? console.log : print;
    var start = new Date().getTime();
    var cnt = 0;
    var res = -1;
    for (;;) {
        res = primes.next();
        cnt++;
        if (cnt % prntCnt === 0) {
            log("Computed " + cnt + " primes in " + (new Date().getTime() - start) + " ms. Last one is " + res);
        }
        if (upto && cnt >= upto) {
            break;
        }
    }
    return new Date().getTime() - start;
}

for (;;) {
    var log = typeof console !== 'undefined' ? console.log : print;
    log("Five thousand prime numbers in " + measure(1000, 5000) + " ms");
}

@@ -19,16 +19,8 @@
 mber
-, filter
 ) %7B%0A
@@ -54,31 +54,49 @@
    this.
-filter = filter
+next = null;%0A    this.last = this
 ;%0A%7D%0AFilt
@@ -114,16 +114,22 @@
 e.accept
+AndAdd
  = funct
@@ -158,16 +158,43 @@
 = this;%0A
+  var sqrt = Math.sqrt(n);%0A
   for (;
@@ -277,89 +277,180 @@
     
-filter = filter.filter;%0A      if (filter === null) %7B%0A          break;%0A      %7D%0A  %7D
+if (filter.number %3E sqrt) %7B%0A          break;%0A      %7D%0A      filter = filter.next;%0A  %7D%0A  var newFilter = new Filter(n);%0A  this.last.next = newFilter;%0A  this.last = newFilter;
 %0A  r
@@ -692,33 +692,8 @@
 null
- %7C%7C this.filter.accept(n)
 ) %7B%0A
@@ -734,23 +734,85 @@
 er(n
-, this.filter);
+);%0A            return n;%0A        %7D%0A        if (this.filter.acceptAndAdd(n)) %7B
 %0A   
@@ -984,20 +984,16 @@
 ural));%0A
-    
 %0A    var
@@ -1333,16 +1333,42 @@
 + res);%0A
+            prntCnt *= 2;%0A
         
@@ -1575,12 +1575,15 @@
 og(%22
-Five
+Hundred
  tho
@@ -1621,15 +1621,15 @@
 ure(
-1000, 5
+97, 100
 000)

Modify the R+js algorithm to also count to one hundred throusand primes