Simple sieve to find smallest prime factors of numbers smaller than MAX
void SieveOfEratosthenes ( ) { for ( int i = 2 ; i * i <= MAX ; ++ i ) { if ( ! prime [ i ] ) for ( int j = i * 2 ; j <= MAX ; j += i ) prime [ j ] = i ; }