from math import log10

def long_sqrt(number, precision=0):
    # Split number into digit pairs
    pairs = [int(number // 10 ** x % 100) for x in range(0, 
int(log10(number) + 1), 2)[::-1]]
    if precision > 0:
        pairs.extend([int(number * 10 ** (2 * x) % 100) for x in 
range(1, precision + 1)])
    # Get the first digit: Solve A^2 <= [first pair]. This is the initial result.
    start = pairs.pop(0)
    result = max(filter(lambda x: x ** 2 <= start, range(10)))
    remainder = start - result ** 2
    while pairs:
        # Bring down two digits
        value = 100 * remainder + pairs.pop(0)
        # Calculate B. Start with its highest possible value, then decrement as necessary
        next_digit = value // 20 // result
        while (result * 20 + next_digit) * next_digit > value:
            next_digit -= 1
        # Plug in B and calculate new remainder
        remainder = value - ((result * 20 + next_digit) * next_digit)
        # Add B to the final result
        result = 10 * result + next_digit
    # If precision was specified, we need to divide to put the decimal point in place. Otherwise, we have our int.
    return result / 10 ** precision if precision else result

# Check sample inputs
assert long_sqrt(7720.17, 0) == 87
assert long_sqrt(7720.17, 1) == 87.8
assert long_sqrt(7720.17, 2) == 87.86
# Run challenge inputs
print(long_sqrt(12345))
print(long_sqrt(123456, 8))
print(long_sqrt(12345678901234567890123456789, 1))