Generate all N digit primes
int L = ( int ) Math . pow ( 10 , N - 1 ) ; int R = ( int ) Math . pow ( 10 , N ) - 1 ; for ( int i = L ; i < R + 1 ; i ++ ) { if ( isPrime ( i ) ) primes . add ( i ) ; } for ( int i = 0 ; i < primes . size ( ) ; i ++ ) {