// $Id: sieve.csharp,v 1.0 2002/02/14 14:02:00 dada Exp $ // http://dada.perl.it/shootout/ using System; class App { public static int Main(String[] args) { int NUM; bool[] flags = new bool[8193]; long i, k; int count = 0; NUM = System.Convert.ToInt32(args[0]); if(NUM < 1) NUM = 1; while(NUM-->0) { count = 0; for(i=2; i <= 8192; i++) { flags[i] = true; } for(i=2; i <= 8192; i++) { if(flags[i]) { // remove all multiples of prime: i for(k=i+i; k <= 8192; k+=i) { flags[k] = false; } count++; } } } Console.WriteLine("Count: " + count.ToString()); return(0); } }