```
class Solution {
public:
int mySqrt(int x) {
if(x==1)
return 1;
double tmp = x/2;
double q = tmp;
while(abs(tmp*tmp-x) > 0.2 ){
if(tmp*tmp > x)
tmp -= q/2;
if(tmp*tmp <x)
tmp += q/2;
q /=2;
}
return int(tmp);
}
};
```