```
class Solution(object):
def mySqrt(self, x):
"""
:type x: int
:rtype: int
"""
return self.sqx(x,1,x)
def sqx(self,x,s,e):
if s>e:
return e
m=(s+e)/2
if x/m==m:
return m
elif x/m<m:
return self.sqx(x,s,m-1)
else:
return self.sqx(x,m+1,e)
```

Newton method-for almost all equation numeric solution

```
class Solution:
# @param x, an integer
# @return an integer
def sqrt(self, x):
epsilon=1.0e-6
a=1.0
if x==0:
return 0
elif x==1:
return 1
else:
while abs(a**2-x)>epsilon:
a=0.5*(a+x/a)
return int(a)
```