```
if(x <= 0)
return 0;
int low = 1;
int high = x;
while(low <= high){
long mid = (long)low + (high - low)/2;
long temp = mid *mid;
if(temp == x)
return mid;
else if(temp > x)
high = mid - 1;
else
low = mid + 1;
}
return high;
```