```
class Solution:
# @param x, an integer
# @return an integer
def sqrt(self, x):
i=x
while i!=0:
j=(i+x/i)/2
if j>=i:
return i
i=j
return i
```

Assume the root is r. If i>r, then x/i<r<i, so j<i, so we should return i when j>=i.