AST
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
608 B

fun sieve(n) {
var nPrimes= 0;
var isPrime= {};
var i= 0;
while (i < n) {
isPrime[i]= 1;
i= i+1;
}
i= 2;
while (i < n) {
if (isPrime[i]) {
nPrimes = nPrimes + 1;
var j= i+i;
while (j < n) {
isPrime[j]= 0;
j= j + i;
}
}
i = i + 1;
}
return nPrimes;
}
start = microseconds();
for (var i= 0; i < 20; i = i + 1) {
print(sieve(8192), "\n");
}
time = microseconds() - start;
secs = time / 1000000;
usec = String(time % 1000000);
while (length(usec) < 6) usec = "0"+usec;
print(secs, ".", usec, " seconds\n");