Buggy python submission (verdict: Runtime Error):
import math
 

def f(n, base):
    X_dumy = base
    lis = []
    while X_dumy > 0:
        lis.append(X_dumy % n)
        X_dumy = X_dumy // n
    return sum(lis)
 
 
def solve():
    N, S = int(input()), int(input())
    # print(N, S)
 
    if N == S:
        return N + 1
 
    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b
 
    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if f(b, N) == S:
            lowest = min(lowest, b)
 
    if not lowest == largest:
        return lowest
 
    return -1
 

if __name__ == '__main__':
    res = solve()
    print(res)


Fixed submission:
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)

Buggy python submission (verdict: Runtime Error):
import math


def f(n, base):
    X_dumy = base
    lis = []
    while X_dumy > 0:
        lis.append(X_dumy % n)
        X_dumy = int(X_dumy / n)
    return sum(lis)


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)


Fixed submission:
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)

Buggy python submission (verdict: Runtime Error):
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    lis = []
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        lis.append(n % base)
        n = n // base
    return sum(lis)


def solve():
    N, S = int(input()), int(input())
    # print(N, S)
 
    if N == S:
        return N + 1
 
    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b
 
    largest = N ** 2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        buf = (N - S) / p
        if buf.is_integer():
            if f(buf + 1, N) == S:
                b = int(buf + 1)
                lowest = min(lowest, b)
 
    if not lowest == largest:
        return lowest
 
    return -1


if __name__ == '__main__':
    res = solve()
    print(res)


Fixed submission:
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)

Buggy python submission (verdict: Runtime Error):
import math

def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    lis = []
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        lis.append(n % base)
        n = n // base
    return sum(lis)


def solve():
    N, S = int(input()), int(input())
    # print(N, S)
 
    if N == S:
        return N + 1
 
    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b
 
    largest = N + 2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        buf = (N - S) / p
        if buf.is_integer():
            if f(buf + 1, N) == S:
                b = int(buf + 1)
                lowest = min(lowest, b)
 
    if not lowest == largest:
        return lowest
 
    return -1


if __name__ == '__main__':
    res = solve()
    print(res)


Fixed submission:
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)

Buggy python submission (verdict: Runtime Error):
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    lis = []
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        lis.append(n % base)
        n = n // base
    return sum(lis)


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N))):
        if f(b, N) == S:
            return b

    largest = N + 2
    lowest = largest
    for p in range(1, int(math.sqrt(N))):
        buf = (N - S) / p
        if buf.is_integer():
            if f(buf + 1, N) == S:
                b = int(buf + 1)
                lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)


Fixed submission:
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)

Buggy python submission (verdict: Runtime Error):
import math


def solve():
    N, S = int(input()), int(input())
    # print(N, S)
    
    floor = math.floor
    def f(b, n):
        if n < b:
            return n
        if n >= b:
            return f(b, floor(n / b)) + (n % b)


    for b in range(2, N):
        if f(b, N) == S:
            return b
    return -1


if __name__ == '__main__':
    res = oracle()
    print(res)


Fixed submission:
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)