/* * Sieve of Erathostenes * Adapted from the Java version at http://dada.perl.it/shootout/sieve.java.html */ import string; void main(char[][] args) { int NUM = string.atoi(args[1]); bit[] flags = new bit[8192 + 1]; int count = 0; while (NUM-- > 0) { count = 0; flags[] = true; for (int i=2; i <= 8192; i++) { if (flags[i]) { // remove all multiples of prime: i for (int k=i+i; k <= 8192; k+=i) flags[k] = false; count++; } } } printf("Count: %i\n", count); }