Buggy python submission (verdict: Runtime Error):
# seishin.py
N, A = map(int, input().split())

ans = N
for k in range(1, 41):
    left = 0; right = N+1
    while left+1 < right:
        mid = (left + right) // 2
        if mid**(k+1) < N:
            left = mid
        else:
            right = mid
    m = right
    v = (m-1)**(k+1)
    for i in range(k+1):
        v //= m-1
        v *= m
        if N <= v:
            ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
            break
print(ans)

Fixed submission:
# seishin.py
N, A = map(int, input().split())

ans = N
if N > 1:
    for k in range(1, 41):
        left = 0; right = N+1
        while left+1 < right:
            mid = (left + right) // 2
            if mid**(k+1) < N:
                left = mid
            else:
                right = mid
        m = right
        v = (m-1)**(k+1)
        for i in range(k+1):
            v //= m-1
            v *= m
            if N <= v:
                ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
                break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())

memo = {1: 1, 0: 0}
def dfs(n):
    if n in memo:
        return memo[n]

    y = 1
    res = n
    while y*y <= n:
        y += 1
        if y + A >= res:
            break
        res = min(res, y + A + dfs((n + y - 1) // y))
    memo[n] = res
    return res
print(dfs(N))

Fixed submission:
# seishin.py
N, A = map(int, input().split())

ans = N
if N > 1:
    for k in range(1, 41):
        left = 0; right = N+1
        while left+1 < right:
            mid = (left + right) // 2
            if mid**(k+1) < N:
                left = mid
            else:
                right = mid
        m = right
        v = (m-1)**(k+1)
        for i in range(k+1):
            v //= m-1
            v *= m
            if N <= v:
                ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
                break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())

memo = {1: 1, 0: 0}
def dfs(n):
    if n in memo:
        return memo[n]

    y = 1
    res = n
    while y*y <= n:
        y += 1
        if y + A > n:
            break
        res = min(res, y + A + dfs((n + y - 1) // y))
    memo[n] = res
    return res
print(dfs(N))

Fixed submission:
# seishin.py
N, A = map(int, input().split())

ans = N
if N > 1:
    for k in range(1, 41):
        left = 0; right = N+1
        while left+1 < right:
            mid = (left + right) // 2
            if mid**(k+1) < N:
                left = mid
            else:
                right = mid
        m = right
        v = (m-1)**(k+1)
        for i in range(k+1):
            v //= m-1
            v *= m
            if N <= v:
                ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
                break
print(ans)

Buggy python submission (verdict: Runtime Error):
# encoding: utf-8
n, a = map(int, raw_input().split())
if n>10**7 or a >= 10**7:
    exit(1)

memo = [-1]*(n+1)
# 残りx個を貯めるために最小の時間を返す予定
def dfs(x):
    if x == 0:
        return 0
    if memo[x] != -1:
        return memo[x]
    i = 0
    res = x
    for i in xrange(2, x+1):
        # i-sec待つ
        res = min(res, dfs((x+i-1)/i)+a+i)
    memo[x] = res
    return memo[x]
print dfs(n)


Fixed submission:
# seishin.py
N, A = map(int, input().split())

ans = N
if N > 1:
    for k in range(1, 41):
        left = 0; right = N+1
        while left+1 < right:
            mid = (left + right) // 2
            if mid**(k+1) < N:
                left = mid
            else:
                right = mid
        m = right
        v = (m-1)**(k+1)
        for i in range(k+1):
            v //= m-1
            v *= m
            if N <= v:
                ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
                break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, a = map(int, raw_input().split())
if n>10**7 or a >= 10**7:
    exit(1)
dp = range(n+1)
ans = n+1
for x in xrange(2, n):
    for i in xrange(x+x, n+1, x):
        dp[i] = min(dp[i], dp[x]+a+i/x)
    ans = min(ans, dp[x]+a+(n+x-1)/x)
print min(ans, dp[-1])


Fixed submission:
# seishin.py
N, A = map(int, input().split())

ans = N
if N > 1:
    for k in range(1, 41):
        left = 0; right = N+1
        while left+1 < right:
            mid = (left + right) // 2
            if mid**(k+1) < N:
                left = mid
            else:
                right = mid
        m = right
        v = (m-1)**(k+1)
        for i in range(k+1):
            v //= m-1
            v *= m
            if N <= v:
                ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
                break
print(ans)