(x)
return y, rem
Correctly rounded integer (floor) square root with remainder.
Correctly rounded integer (floor) square root with remainder.
Correctly rounded integer ( floor ) square root with remainder .
def sqrtrem_python(x):
    """Correctly rounded integer (floor) square root with remainder."""
    # to check cutoff:
    # plot(lambda x: timing(isqrt, 2**int(x)), [0,2000])
    if x < _1_600:
        y = isqrt_small_python(x)
        return y, x - y*y
    y = isqrt_fast_python(x) + 1
    rem = x - y*y
    # Correct remainder
    while rem < 0:
        y -= 1
        rem += (1+2*y)
    else:
        if rem:
            while rem > 2*(1+y):
                y += 1
                rem -= (1+2*y)
    return y, rem
def sqrtrem_python ( x ) : # to check cutoff: # plot(lambda x: timing(isqrt, 2**int(x)), [0,2000]) if x < _1_600 : y = isqrt_small_python ( x ) return y , x - y * y y = isqrt_fast_python ( x ) + 1 rem = x - y * y # Correct remainder while rem < 0 : y -= 1 rem += ( 1 + 2 * y ) else : if rem : while rem > 2 * ( 1 + y ) : y += 1 rem -= ( 1 + 2 * y ) return y , rem