If n is divisible by any number between 2 and Math . sqrt ( n ) , it is not prime
for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { flag = 0 ; break ; } } return ( flag == 1 ? true : false ) ; }