Using sieve of Eratosthenes to find all prime upto N
static void sieve ( int N ) { prime . Insert ( 0 , false ) ; prime . Insert ( 1 , false ) ; for ( int i = 2 ; i <= N ; i ++ ) { if ( prime [ i ] ) { for ( int j = 2 ; i * j <= N ; j ++ ) { prime . Insert ( i * j , false ) ; } } } }