/* The Computer Language Shootout
   http://shootout.alioth.debian.org/

   contributed by Nicolas Cannasse
*/
fmt = function(i) {
	var s = $string(i);
	while( $ssize(s) < 8 )
		s = " "+s;
	return s;
}
nsieve = function(m) {
	var a = $amake(m);
	var count = 0;
	var i = 2;
	while( i < m ) {
		if $not(a[i]) {
			count += 1;
			var j = (i << 1);
			while( j < m ) {
				if( $not(a[j]) ) a[j] = true;
				j += i;
			}
		}
		i += 1;
	}
	$print("Primes up to ",fmt(m)," ",fmt(count),"\n");
}

var n = $int($loader.args[0]);
if( n == null ) n = 2;
var i = 0;
while( i < 3 ) {
	nsieve(10000 << (n - i));
	i += 1;
}
