def nth_root(x, n):
    """Finds the nearest integer root of a number."""
    upper = 1
    while upper ** n <= x:
        upper *= 2

    mid, lower = None, upper // 2

    while lower != upper:
        mid = (lower + upper) // 2
        mid_n = mid ** n
        if lower < mid and mid_n < x:
            lower = mid
        elif upper > mid and mid_n > x:
            upper = mid
        else:
            return mid

    if mid is not None:
        return mid + 1