Function to precompute all the primes upto 1000000 and store it in a set using Sieve of Eratosthenes
static void getPrimesFromSeive ( HashSet < String > primes ) { bool [ ] prime = new bool [ 1000001 ] ; for ( int i = 0 ; i < 1000001 ; i ++ ) prime [ i ] = true ; prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= 1000000 ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * i ; j <= 1000000 ; j += i ) prime [ j ] = false ; } }