// $Id: sieve.elastic,v 1.0 2002/05/17 10:07:00 dada Exp $
package sieve;

import basic;
import sys;
import array;

private n = 1;
private i, k;
private result = 0;
private flags = #[];
private count;
if(array.length(sys.args) > 0) {
    n = basic.int(sys.args[0]);
} else {
    n = 1;
}
while(n--) {
    count = 0;
    for (i=2; i <= 8192; i++) {
        flags[i] = 1;
    }
    for (i=2; i <= 8192; i++) {
        if (flags[i]) {
        // remove all multiples of prime: i
        for (k=i+i; k <= 8192; k=k+i) {
            flags[k] = 0;
        }
        count++;
        }
    }
}
basic.print("Count: ", count);