Sieve of Eratosthenes
static void sieve ( ) { for ( int i = 0 ; i < primes . Length ; i ++ ) { primes [ i ] = true ; } primes [ 0 ] = false ; primes [ 1 ] = false ; for ( int i = 2 ; i * i <= maxn ; i ++ ) { if ( primes [ i ] ) { for ( int j = i * i ; j <= maxn ; j += i ) primes [ j ] = false ; } } }