class BeaconStateUtil {

  public static UInt64 integer_squareroot(UInt64 n) {
    checkArgument(
        n.compareTo(UInt64.ZERO) >= 0, "checkArgument threw an exception in integer_squareroot()");
    UInt64 x = n;
    UInt64 y = x.plus(UInt64.ONE).dividedBy(2);
    while (y.compareTo(x) < 0) {
      x = y;
      y = x.plus(n.dividedBy(x)).dividedBy(2);
    }
    return x;
  }

}