/* The Great Win32 Language Shootout http://dada.perl.it/shootout/
contributed by Isaac Gouy (Nice novice)
To compile:
nicec --sourcepath=.. -d=. -a sieve.jar sieve
To run:
java -jar sieve.jar 900
*/
// NOTE: the type of constants & variables declared with
// let & var will be inferred by the compiler
import ackermann; // reuse toSingleInt
void main(String[] args){
var n = toSingleInt(args);
let start = 2;
let stop = 8192;
var isPrime = new boolean[stop+1];
var count = 0;
while (n-- > 0){
count = 0;
for(var i=start; i <= stop; i++) isPrime[i] = true;
for(var i=start; i <= stop; i++)
if(isPrime[i]) {
// remove all multiples of prime: i
for(var k=i+i; k <= stop; k+=i) isPrime[k] = false;
count++;
}
}
println("Count: " + count);
}