let isqrt n =
  if n < 2 then n
  else
    let x = ref n in
    let y = ref ((!x + 1) / 2) in
    while !y < !x do
      x := !y;
      y := (!x + n / !x) / 2
    done;
    !x

;;

isqrt 144 + isqrt 200 + isqrt 1000000 + isqrt 2
