Function to precompute all the primes upto 1000000 and store it in a set using Sieve of Eratosthenes
void getPrimesFromSeive ( set < string > & primes ) { bool prime [ 1000001 ] ; memset ( prime , true , sizeof ( prime ) ) ; 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 ; } }