sieve method for prime calculation
bool [ ] hash = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) hash [ i ] = true ; for ( int p = 2 ; p * p < n ; p ++ ) if ( hash [ p ] == true ) for ( int i = p * 2 ; i < n ; i += p ) hash [ i ] = false ;