

public class demoEZ69 {
public static void main(String[] args) {
System.out.println(mySqrt(9));
}
public static int mySqrt(int x){ // when x == 25
int l = 0, r = x, ans = -1;
while(l <= r){ //while (l <= 25) //4 <= 5
int mid = 1 + (r-1) /2; // mid == 13 //mid == 6 //mid ==3
if((long) mid* mid <= x){ // if((long)169 <= 25) //if((long)36 <= 25)
ans = mid; //ans == 9 //ans == 3
l = mid + 1;// l == 3 + 1 ==4
}else{
r = mid -1; //r == 13 - 1 ==12 //r == 6-1 == 5
}
}
return ans;
}
}