TITLE: Fast algorithm for computing integer square roots on machines that doesn't support floating-point arithmetic?
QUESTION [5 upvotes]: Fast algorithm for computing integer square roots on machines that doesn't support floating-point arithmetic?

I'm looking for a fast algorithm for computing the integer square root of an integer $N \ge 0$, i.e., the smallest integer $m \ge 0$, s.t., $m^2 \le N < (m+1)^2$.
The reason is that I'm operating on a virtual machine that doesn't support floating-point arithmetic (real-numbers), so algorithms like Newton's cannot be implemented, right?
The naive solution for finding the square root of $N$ is to check for $m=0,1,\ldots$ whether $m^2 \le N < (m+1)^2$. Is this the best algorithm?

REPLY [8 votes]: I think the easiest method will Babylonians sqrt method and it works well with machine supporting only integer division.
def babylonian(n):
x = n
y = 1
while(x > y):
    x = (x+y)//2
    y = n//x
return x