Create a boolean vector " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true .
vector < bool > prime ( max_val + 1 , true ) ; for ( int p = 2 ; p * p <= max_val ; p ++ ) {