#include #include using namespace std; // Fixed binarySearch uses call-by-constant reference int binarySearch( const vector & arr, int x ) { int low = 0, high = arr.size( ) - 1; while( low <= high ) { int mid = ( low + high ) / 2; if( arr[ mid ] == x ) return mid; else if( x < arr[ mid ] ) high = mid - 1; else low = mid + 1; } return -1; // not found } int main( ) { vector v; for( int i = 0; i < 30000; i++ ) v.push_back( i * i ); for( int j = 100000; j < 105000; j++ ) if( binarySearch( v, j ) >= 0 ) cout << j << " is a perfect square" << endl; return 0; }