Problem:


Score : 1000 points

Problem Statement

Rng is baking cookies.

Initially, he can bake one cookie per second.

He can also eat the cookies baked by himself.
When there are x cookies not yet eaten, he can choose to eat all those cookies. After he finishes eating those cookies, the number of cookies he can bake per second becomes x. Note that a cookie always needs to be baked for 1 second, that is, he cannot bake a cookie in 1/x seconds when x > 1.
When he choose to eat the cookies, he must eat all of them; he cannot choose to eat only part of them.
It takes him A seconds to eat the cookies regardless of how many, during which no cookies can be baked.

He wants to give N cookies to Grandma.
Find the shortest time needed to produce at least N cookies not yet eaten.

Constraints

1≦N≦10^{12}

0≦A≦10^{12}

A is an integer.

Partial Score

500 points will be awarded for passing the test set satisfying N≦10^6 and A≦10^6.

Additional 500 points will be awarded for passing the test set without additional constraints.

Input

The input is given from Standard Input in the following format:

N A

Output

Print the shortest time needed to produce at least N cookies not yet eaten.

Sample Input 1

8 1

Sample Output 1

7

It is possible to produce 8 cookies in 7 seconds, as follows:

After 1 second: 1 cookie is done.

After 2 seconds: 1 more cookie is done, totaling 2. Now, Rng starts eating those 2 cookies.

After 3 seconds: He finishes eating the cookies, and he can now bake 2 cookies per second.

After 4 seconds: 2 cookies are done.

After 5 seconds: 2 more cookies are done, totaling 4.

After 6 seconds: 2 more cookies are done, totaling 6.

After 7 seconds: 2 more cookies are done, totaling 8.

Sample Input 2

1000000000000 1000000000000

Sample Output 2

1000000000000



Sample input:
8 1


Sample output:
7

Submission status: Wrong Answer

Solution code:
N,A=map(int,input().split())

ans=N

for i in range(-10,10):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,41):
    for i in range(2*n,82):
        test=i+n*A
        q=i//n
        r=i%n
        prod=pow(q,n-r)*pow(q+1,r)
        test+=(N-1)//prod+1
        ans=min(ans,test)

print(ans)

Submission status: Wrong Answer

Solution code:
N,A=map(int,input().split())

ans=N

for i in range(-5,5):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,41):
    for i in (n,0,-1):
        for x in range(2,int(N**(1/n))+1000):
            test=x*i+(x+1)*(n-i)
            last=pow(x,i)*pow(x+1,n-i)
            test+=(N-1)//last+1+n*A
            ans=min(ans,test)

print(ans)

Submission status: Wrong Answer

Solution code:
N,A=map(int,input().split())

ans=N

for i in range(-5,5):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,41):
    for i in (n,0,-1):
        for x in range(2,int(N**(1/n))+5):
            test=x*i+(x+1)*(n-i)
            last=pow(x,i)*pow(x+1,n-i)
            test+=(N-1)//last+1+n*A
            ans=min(ans,test)

print(ans)

Submission status: Wrong Answer

Solution code:
N,A=map(int,input().split())

ans=N

for i in range(-5,5):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,41):
    for i in (n,0,-1):
        for x in range(2,int(N**(1/n))+2):
            test=x*i+(x+1)*(n-i)
            last=pow(x,i)*pow(x+1,n-i)
            test+=(N-1)//last+1+n*A
            ans=min(ans,test)

print(ans)

Submission status: Wrong Answer

Solution code:
N,A=map(int,input().split())

ans=N

for i in range(-5,5):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,40):
    for i in (n,0,-1):
        for x in range(2,int(N**(1/n))+2):
            test=x*i+(x+1)*(n-i)
            last=pow(x,i)*pow(x+1,n-i)
            test+=(N-1)//last+1+n*A
            ans=min(ans,test)

print(ans)

Submission status: Wrong Answer

Solution code:
n,a = map(int,input().split())
if n == 1:
  print(1)
  exit()
if n <= a:
  print(n)
  exit()
l = -1
r = 10**12+1
#n <= x**(k-i)*(x-1)**iのk-iを返す
def border(x,k):
  if k >= 45:
    return (n-1).bit_length()
  else:
    L = 0
    R = k
    while L+1 < R:
      M = (L+R)//2
      if x**(k-M)*(x-1)**(M) < n:
        R = M
      else:
        L = M
    return k-L
def sec(k):
  if k == 0:
    return n
  if k >= 45:
    x = 2
  else:
    y = int(n**(1/k))+1
    if (y-1)**k < n <= y**k:
      x = y
    elif y**k < n <= (y+1)**k:
      x = y+1
    elif (y-2)**k < n <= (y-1)**k:
      x = y-1
  b = border(x,k)
  return (x+a)*k-(k-b)

while l+2 < r:
  ml = (l*2+r)//3
  mr = (l+r*2)//3
  if sec(ml) < sec(mr):
    r = mr
  else:
    l = ml
if l+1 == 0:
  print(n)
else:
  print(sec(l+1)-a)

Submission status: Wrong Answer

Solution code:
n,a = map(int,input().split())
if n == 1:
  print(1)
  exit()
l = -1
r = 10**12+1
#n <= x**(k-i)*(x-1)**iのk-iを返す
def border(x,k):
  if k >= 40:
    return (n-1).bit_length()
  else:
    L = 0
    R = k
    while L+1 < R:
      M = (L+R)//2
      if x**(k-M)*(x-1)**(M) < n:
        R = M
      else:
        L = M
    return k-L
def sec(k):
  if k == 0:
    return n
  if k >= 40:
    x = 2
  else:
    y = int(n**(1/k))+1
    if (y-1)**k < n <= y**k:
      x = y
    elif y**k < n <= (y+1)**k:
      x = y+1
    elif (y-2)**k < n <= (y-1)**k:
      x = y-1
  b = border(x,k)
  return (x+a)*k-(k-b)

while l+2 < r:
  ml = (l*2+r)//3
  mr = (l+r*2)//3
  if sec(ml) < sec(mr):
    r = mr
  else:
    l = ml
if l+1 == 0:
  print(n)
else:
  print(sec(l+1)-a)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

def check(x):
    if x - 50*A >= 100:
        return N+1
    right = x if not A else x//A
    left = 1
    res = x
    for l in range(left, right+1):
        cl = calc(l, x-(l-1)*A)
        if res < cl:
            res = cl
    return res
    
    
def calc(k, c):
    return pow(c//k+1, c%k)*pow(c//k, k-c%k)

N, A = map(int, readline().split())


ok = N
ng = 0
while abs(ok-ng)>1:
    med = (ok+ng)//2
    if check(med) >= N:
        ok = med
    else:
        ng = med
    
print(ok)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

def check(x):
    if x - 50*A >= 100:
        return N+1
    right = x if not A else x//A
    left = 1
    while abs(right - left) > 2:
        med1 = (left*2+right)//3
        med2 = (left+right*2)//3
        r1 = calc(med1, x-(med1-1)*A)
        r2 = calc(med2, x-(med2-1)*A)
        if r1 == -1 or r2 == -1:
            return N+1
        if r1 < r2:
            left = med1
        else:
            right = med2
    
    res = x
    for l in range(left, right+1):
        cl = calc(l, x-(l-1)*A)
        if res < cl:
            res = cl
    return res
    
    
def calc(k, c):
    return pow(c//k+1, c%k)*pow(c//k, k-c%k)

N, A = map(int, readline().split())


ok = N
ng = 0
while abs(ok-ng)>1:
    med = (ok+ng)//2
    if check(med) >= N:
        ok = med
    else:
        ng = med
    
print(ok)

Submission status: Wrong Answer

Solution code:
def examA():
    H, W = LI()
    S = [LSI() for _ in range(H)]
    Alpha = [chr(ord('A') + i) for i in range(26)]
    for i in range(H):
        for j in range(W):
            if S[i][j]=="snuke":
                ans = str(Alpha[j]) + str(i+1)
    print(ans)
    return

def examB():
    N = I()
    ans = []
    cur = int((N*2-1)**0.5)+1
    ansC = (cur+1)*cur//2
    neg = ansC-N
    if neg>cur:
        cur -=1
        ansC = (cur + 1) * cur // 2
        neg = ansC - N
    for i in range(1,cur+1):
        if i!=neg:
            ans.append(i)
    for v in ans:
        print(v)
#    print(cur,neg)
    return

def bfs(n,e,fordfs):
    #点の数、スタートの点、有向グラフ
    que = deque()
    que.append(e)
    len = [10**9]*n
    len[e] = 0
    while que:
        now = que.popleft()
        nowlen = len[now]
        for ne in fordfs[now]:
            if len[ne] == 10**9:
                len[ne] = nowlen+1
                que.append(ne)
    return len
def examC():
    N, M = LI()
    V = [[]for _ in range(N+M)]
    for i in range(N):
        L = LI()
        for k in range(1,L[0]+1):
            V[i].append(L[k]+N-1)
            V[L[k]+N-1].append(i)
    length = bfs(N+M,0,V)
    ans = "YES"
    for i in length[:N]:
        if i==10**9:
            ans = "NO"
    print(ans)
    return

def examD():
    N, M = LI()
    X = LI(); maxX = max(X)+1
    dx = defaultdict(int)
    dm = [set()for _ in range(M)]
    d = defaultdict(int)
    for x in X:
        dx[x] +=1
        d[x%M] +=1
        dm[x%M].add(x)
    ans = 0
#    print(d); print(dx); print(dm)
    ans +=d[0]//2
    d[0] = 0
    for i in range(1,1+M//2):
        cur = min(d[i],d[M-i])
        ans +=cur
        d[i] -=cur; d[M-i] -=cur
#    print(ans); print(d)
    for i in d.keys():
        for j in dm[i]:
            cur = min(dx[j]//2,d[i]//2)
            d[i] -= cur * 2
            ans += cur
            if d[i]<=1:
                break
    print(ans)
    return

def caneat(x,A,n):
    cur = n - A*x
    l = cur//(x+1); r = cur%(x+1)
    if l==0:
        return 1
    now = pow(l,(x-r+1))*pow((l+1),r)
    return now
def ternarySearch(A,n,e):
    #何回喰うか
    fr, to = 0, e
    while to - fr > 2:
        x1, x2 = (2 * fr + to)//3, (2 * to + fr)//3
        f1, f2 = caneat(x1,A,n), caneat(x2,A,n)
        if f1 > f2:
            to = x2
        elif f1 < f2:
            fr = x1
        else:
            fr, to = x1, x2
    return max(caneat(fr,A,n),caneat(fr+1,A,n),caneat(to,A,n))
def examE():
    N, A = LI()
    l = 0; r = N+1
    while(r-l>1):
        now = (l+r)//2
        maxE = now//(A+1)
        cur = ternarySearch(A,now,maxE)
        if N<=cur:
            r = now
        else:
            l = now
#        print(l,r,cur)
#    print(l,r)
    if A>=N//2:
        ans = N
    else:
        ans = r
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examE()

Submission status: Wrong Answer

Solution code:
import math


def main():
    N, A = map(int, input().split())
    ans = float("inf")
    for i in range(41):
        x = N**(1/(i+1))
        y = math.ceil(x * (i+1)) + A * i
        ans = min(ans, y)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, A = map(int, input().split())

ans = N
x = 1
while x*x <= N:
    x += 1
    y = 1
    c = 0
    while y <= N:
        y *= x
        c += 1
        ans = min(ans, (x + A)*c + (N + y - 1) // y)
print(ans)

Submission status: Wrong Answer

Solution code:
N, A = map(int, input().split())

ans = N
x = 2
while x*x <= N:
    y = 1
    c = 0
    while y <= N:
        y *= x
        c += 1
        ans = min(ans, (x + A)*c + (N + y - 1) // y)
    x += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

N, A = map(int, input().split())
if N > 10**6 and A > 10**6:
    print(N)
    sys.exit()
dp = [float('inf') for _ in range(2 * N + 1)]
dp[0] = 0
for i in range(1, N):
    for j in range(i, 2 * N, j):
        dp[j] = max(dp[j], dp[i] + A + j // i)
print(min(dp[N:]))

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10 ** 6 or A > 10 ** 6:
    print(-1)
    sys.exit()
dp = [float("inf")] * (N+1)
dp[1] = 0
for i in range(1, N//2+1):
    for n, j in enumerate(range(i+i, N, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N//2+2))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10 ** 6 or A > 10 ** 6:
    print(-1)
    sys.exit()
dp = [float("inf")] * (N+1)
dp[1] = 0
for i in range(1, N//2+1):
    for n, j in enumerate(range(i+i, N+1, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N//2+1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10 ** 6 or A > 10 ** 6:
    print(-1)
    sys.exit()
dp = [float("inf")] * (N+1)
dp[1] = 0
for i in range(1, N//2+1):
    for n, j in enumerate(range(i+i, N, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N//2+1))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def pow(a, b):
    if b == 1:return a
    if b%2 == 0:
        return pow(a*a, int(b/2))
    return a*pow(a*a, int(b/2))

def binaryOne(n, multi):
    l = 0
    r = n
    mid = (l + r)/2
    while r - l > 1:
        if pow(mid, multi) > n:
            r = mid
        else:
            l = mid
        mid = (r + l)/2
    return r;


def binaryTwo(n, maxi, multi):
    l = 0
    r = multi
    mid = (l + r)/2;
    while r - l > 1:
        if pow(maxi, (multi - mid))*pow(maxi - 1, mid) >= n:
            l = mid
        else:
            r = mid
        mid = (r + l)/2;
    return l

n, a = map(int,raw_input().split(" "))
ans = 1e18
for i in xrange(0, 40):
    maxi = binaryOne(n, i + 1);
    subt = binaryTwo(n, maxi, i + 1)
    ans = min(ans, a*i + maxi*(i + 1) - subt)
    
print ans

Submission status: Wrong Answer

Solution code:
from math import ceil
import sys

n, a = map(int, next(sys.stdin).strip().split())

stats = [(0, 1, 2)]
time = n
while len(stats) > 0:
    t, s, k = stats.pop(0)
    time = min(time, t + ceil(n / s))
    for d in range(k, 2 + a + 1):
        stats.append((t + d + a, d * s, d))
    stats = sorted((t, s, k) for t, s, k in stats if t < time)
print(time)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10 ** 6 or A > 10 ** 6:
    print(-1)
    sys.exit()
dp = [float("inf")] * (N+1)
dp[1] = 0
ans = float("inf")
for i in range(1, N+1):
    for n, j in enumerate(range(i+i, N+1, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N+1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10 ** 6 or A > 10 ** 6:
    print(-1)
    sys.exit()
dp = [float("inf")] * N
dp[1] = 0
ans = float("inf")
for i in range(1, N//2+1):
    tmp = dp[i] + ceil(N/i)
    ans = min(ans, tmp)
    for n, j in enumerate(range(i+i, N//2+1, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10 ** 6 or A > 10 ** 6:
    print(-1)
    sys.exit()
dp = [float("inf")] * N
dp[1] = 0
for i in range(1, N//2+1):
    for n, j in enumerate(range(i+i, N//2+1, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N//2+1))
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
n, a = map(int, raw_input().split())

dic = {0: 0, 1: 1}
# 残りx個を貯めるために最小の時間を返す予定
def dfs(x):
    if x in dic:
        return dic[x]
    res = x
    left = 2; right = x+1
    for i in xrange(40):
        m1 = (left*2+right)/3; m2 = (left+right*2)/3
        r1 = dfs((x+m1-1)/m1)+a+m1
        r2 = dfs((x+m2-1)/m2)+a+m2
        if r1 < r2:
            right = m2+1
        else:
            left = m1
    for i in xrange(left, right):
        r = dfs((x+i-1)/i)+a+i
        if r > res:
            break
        res = r
    dic[x] = res
    return res
print dfs(n)

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
n, a = map(int, raw_input().split())

dic = {0: 0, 1: 1}
# 残りx個を貯めるために最小の時間を返す予定
def dfs(x):
    if x in dic:
        return dic[x]
    res = x
    left = 2; right = x+1
    for i in xrange(40):
        m1 = (left*2+right)/3; m2 = (left+right*2)/3
        r1 = dfs((x+m1-1)/m1)+a+m1
        r2 = dfs((x+m2-1)/m2)+a+m2
        if r1 < r2:
            right = m2+1
        else:
            left = m1
    for i in xrange(left, right):
        res = min(res, dfs((x+i-1)/i)+a+i)
    dic[x] = res
    return res
print dfs(n)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
import sys

def test(period):
    cps = 1
    t = 0
    eat_cnt = 0
    while True:
        if math.ceil(N / cps) > period + A + math.ceil(N / (cps * period)):
            t += period + A
            cps *= period
            eat_cnt += 1
        else:
            t += N / cps
            break
    p_cnt = 0
    while eat_cnt > 0:
        nt = t - 1 + N / (cps * (period - 1))
        if nt < t:
            cps *= (period-1) / period
            t = nt
            p_cnt += 1
            eat_cnt -= 1
        else:
            break
    if period > 2:
        while p_cnt > 0:
            nt = t - 1 + N / (cps * (period - 2))
            if nt < t:
                cps *= (period-2) / (period-1)
                t = nt
                p_cnt -= 1
            else:
                break
    return math.ceil(t)


def solve():
    if N == 1:
        return 1, 1
    ans = N
    ans_p = None
    i = 1
    f = False
    while True:
        if f:
            break
        p = math.ceil(math.pow(N, 1/i))
        if p <= 2:
            f = True
        t = test(p)
        if ans > t:
            ans = t
            ans_p = p
        i += 1
    return ans, ans_p


N, A = map(int, input().split())
ans, ans_p = solve()

print(ans)
sys.stderr.write(str(ans_p))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
import sys

def test(period):
    cps = 1
    t = 0
    while True:
        if math.ceil(N / cps) > period + A + math.ceil(N / (cps * period)):
            t += period + A
            cps *= period
        else:
            t += N / cps
            break
    while True:
        nt = t - 1 + N / (cps * (period - 1))
        if nt < t:
            cps *= (period-1) / period
            t = nt
        else:
            break
    if period > 2:
        while True:
            nt = t - 1 + N / (cps * (period - 2))
            if nt < t:
                cps *= (period-2) / (period-1)
                t = nt
            else:
                break
    return math.ceil(t)


def solve():
    if N == 1:
        return 1, 1
    ans = N
    ans_p = None
    i = 1
    f = False
    while True:
        if f:
            break
        p = math.ceil(math.pow(N, 1/i))
        if p <= 2:
            f = True
        t = test(p)
        if ans > t:
            ans = t
            ans_p = p
        i += 1
    return ans, ans_p


N, A = map(int, input().split())
ans, ans_p = solve()

print(ans)
sys.stderr.write(str(ans_p))

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
n, a = map(int, raw_input().split())

dic = {1: 1}
# 残りx個を貯めるために最小の時間を返す予定
def dfs(x):
    if x == 0:
        return 0
    #print x
    if x in dic:
        return dic[x]
    i = 0
    res = x
    left = 2; right = x+1
    for i in xrange(40):
        m1 = (left*2+right)/3; m2 = (left+right*2)/3
        r1 = dfs((x+m1-1)/m1)+a+m1
        r2 = dfs((x+m2-1)/m2)+a+m2
        if r1 < r2:
            right = m2+1
        else:
            left = m1
    res = min(res, r1, r2)
    dic[x] = res
    return res
print dfs(n)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def test(period):
    cps = 1
    t = 0
    while True:
        if math.ceil(N / cps) > period + A + math.ceil(N / (cps * period)):
            t += period + A
            cps *= period
        else:
            t += N / cps
            break
    while True:
        nt = t - 1 + N / (cps * (period-1))
        if nt < t:
            cps *= (period-1) / period
            t = nt
        else:
            return math.ceil(t)


def solve():
    if N == 1:
        return 1, 1
    ans = N
    ans_p = None
    i = 1
    f = False
    while True:
        if f:
            break
        p = math.ceil(math.pow(N, 1/i))
        if p <= 2:
            f = True
        t = test(p)
        if ans > t:
            ans = t
            ans_p = p
        i += 1
    return ans, ans_p


N, A = map(int, input().split())
ans, ans_p = solve()

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def test(period):
    cps = 1
    t = 0
    while True:
        if math.ceil(N / cps) > period + A + math.ceil(N / (cps * period)):
            t += period + A
            cps *= period
        else:
            t += N / cps
            break
    while True:
        nt = t - 1 + N / (cps * (period-1))
        if nt < t:
            cps *= (period-1) / period
            t = nt
        else:
            return math.ceil(t)

N, A = map(int, input().split())
ans = N
ans_p = None

i = 1
f = False
while True:
    if f:
        break
    p = math.ceil(math.pow(N, 1/i))
    if p <= 2:
        f = True
    t = test(p)
    if ans > t:
        ans = t
        ans_p = p
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def test(period):
    # period秒クッキーを焼いては食べることを繰り返す
    # 食べないほうが早く焼き終わるまで続ける
    cps = 1
    t = 0
    while True:
        if math.ceil(N / cps) > period + A + math.ceil(N / (cps * period)):
            t += period + A
            cps *= period
        else:
            t += math.ceil(N / cps)
            return t


N, A = map(int, input().split())
ans = N
ans_p = None

r = A * 10 if A < 10000 else A
ans_p = None
for i in range(1, r + 1):
    t = test(i)
    if ans > t:
        ans = t
        ans_p = i
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def test(period):
    # period秒クッキーを焼いては食べることを繰り返す
    # 食べないほうが早く焼き終わるまで続ける
    cps = 1
    t = 0
    while True:
        if math.ceil(N / cps) > period + A + math.ceil(N / (cps * period)):
            t += period + A
            cps *= period
        else:
            t += math.ceil(N / cps)
            return t


N, A = map(int, input().split())
ans = N
ans_p = None

r = A * 10 if A < 10000 else A
for i in range(1, A * 10 + 1):
    t = test(i)
    if ans > t:
        ans = t
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(N, A) = reads()

c = [0] * (N+1)

for i in range(A+1):
  c[i] = i

for i in range(A+1, N+1):
  c[i] = max(i, max(c[j]*(i-j-A) for j in range(i-A)))
  if c[i] >= N:
    print(i)
    # print(c[:i+1])
    exit()

Submission status: Time Limit Exceeded

Solution code:
N,A=map(int,input().split())

ans=N
for n in range(1,41):
    for i in range(2*n,int(N**(1/n))+100):
        test=i+n*A
        q=i//n
        r=i%n
        prod=pow(q,n-r)*pow(q+1,r)
        test+=(N-1)//prod+1
        ans=min(ans,test)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

N, A = map(int, input().split())
if N > 10**6 and A > 10**6:
    print(N)
    sys.exit()
dp = [float('inf') for _ in range(2 * N + 1)]
dp[0] = 0
for i in range(N):
    for j in range(i, 2 * N, j):
        dp[j] = max(dp[j], dp[i] + A + j // i)
print(min(dp[N:]))

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10 ** 6 or A > 10 ** 6:
    raise
dp = [float("inf")] * (N+1)
dp[1] = 0
ans = float("inf")
for i in range(1, N+1):
    for n, j in enumerate(range(i+i, N+1, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N+1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
N, A = [int(i) for i in input().split()]
dp = [float("inf")] * N
dp[1] = 0
for i in range(1, N//2+1):
    for n, j in enumerate(range(i+i, N//2+1, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N//2+1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
N, A = [int(i) for i in input().split()]
dp = [float("inf")] * N
dp[1] = 0
for i in range(1, N//2):
    for n, j in enumerate(range(i+i, N, i), start=2):
        dp[j] = min(dp[j], dp[i]+n+A)
ans = min(dp[i]+ceil(N/i) for i in range(1, N//2+1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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])

Submission status: Accepted

Solution code:
def fast_pow(x, y):
    if y == 0:
        return 1
    p = fast_pow(x, y // 2)
    p = p * p
    if y % 2:
        p = p * x
    return p


n, a = list(map(int, input().split()))
maxM = 1
d = 1
while n >= d:
    maxM += 1
    d *= 2

r = n
l = 0
while r - l > 1:
    mid = (r + l) // 2

    for m in range(2, maxM + 1):
        if (mid + a) % m == 0:
            if (mid + a) // m - a < 1:
                continue
            if fast_pow((mid + a) // m - a, m) >= n:
                r = mid
                break
        else:
            a1 = (mid + a + m - 1) // m - a
            a2 = (mid + a) // m - a
            if a1 < 1 or a2 < 1:
                continue

            if fast_pow(a1, (mid + a) % m) * fast_pow(a2, m - (mid + a) % m) >= n:
                r = mid
                break
    else:
        l = mid
print(r)

Submission status: Accepted

Solution code:

"""

https://atcoder.jp/contests/cf16-final/tasks/codefestival_2016_final_e

部分点を考えてみる
dp[i] = i枚を焼くのにかかる最小の時間　としてみる
初期値は, dp[i] = i
dp[i] <- dp[j] + A*j + (i+j-1)//j
これだと部分点も取れない

Aって結構でかそうだよな…
dp[i+1] <= dp[i] + 1
である。つまり、差は0か1
これは、少なくとも1秒待てば焼けることから証明できる

推移先は、 dp[j] + A*j 以上なのは確定


そして掛け算であるということは順番を入れ替えることができる
(((1×4秒)×5秒)×3秒)=60枚(編集済)
順番を入れ替えても
(((1×3秒)×4秒)×5秒)=60枚
by werug

積がx以上となる数列aで、
a1+a2+a3+…+an + A×(n-1)
が最小となるものを見つけなさい
n <= 40　くらい

n個の数列で、積がX以上になるうち
和が最小のものを求めなさい → これを 1<=n<=40 に対して計算すればいい

和を最小化するには、できるだけ同じ数字で分散させるのが最適…？(編集済)
12の時、 1x12 , 2x6 , 3x4 だと 3x4が一番輪が小さい
整数以外も可能なら, X^(-n) づつが最適
整数だとceil (X^(-n)) と、floor(X^(-n)) を一定個数づつ混ぜるのが最適のはず(編集済)
→全探索できる

"""

from sys import stdin
N,A = map(int,stdin.readline().split())

ans = N
for s in range(1,45): #sは数列の長さ

    if 2**s >= N:
        ans = min( ans , 2*s + A*(s-1) )
        continue

    nm = int(N**(1/s))
    #print (s,nm)
    for t in range(s+1):
        if pow(nm,t) * pow(nm+1,s-t) >= N:
            ans = min(ans , nm*t+(nm+1)*(s-t) + A*(s-1) )

print (ans)

#実験
"""
dp = [i for i in range(N+1)]

for i in range(N+1):
    for j in range(1,i):
        dp[i] = min(dp[i] , dp[j] + A + (i+j-1)//j )

print (dp)
"""

Submission status: Accepted

Solution code:
N,A=map(int,input().split())

ans=N

for i in range(-5,5):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,41):
    for i in range(n,0,-1):
        for x in range(2,int(N**(1/n))+1000):
            test=x*i+(x+1)*(n-i)
            last=pow(x,i)*pow(x+1,n-i)
            test+=(N-1)//last+1+n*A
            ans=min(ans,test)

print(ans)

Submission status: Accepted

Solution code:
N,A=map(int,input().split())

ans=N

for i in range(-10,10):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,41):
    for i in range(2*n,int(N**(1/n))+1000):
        test=i+n*A
        q=i//n
        r=i%n
        prod=pow(q,n-r)*pow(q+1,r)
        test+=(N-1)//prod+1
        ans=min(ans,test)

print(ans)

Submission status: Accepted

Solution code:
n,a = map(int,input().split())
if n == 1:
  print(1)
  exit()
if n <= a:
  print(n)
  exit()
#n <= x**(k-i)*(x-1)**iのk-iを返す
def border(x,k):
  L = 0
  R = k
  while L+1 < R:
    M = (L+R)//2
    if x**(k-M)*(x-1)**(M) < n:
      R = M
    else:
      L = M
  return k-L
def sec(k):
  y = int(n**(1/k))+1
  if (y-1)**k < n <= y**k:
    x = y
  elif y**k < n <= (y+1)**k:
    x = y+1
  elif (y-2)**k < n <= (y-1)**k:
    x = y-1
  b = border(x,k)
  return (x+a)*k-(k-b)
ansls = []
for i in range(1,51):
  ansls.append(sec(i))
print(min(ansls)-a)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def check(x):
    if x - 50*A >= 100:
        return N+1
    right = (x+A)//(1+A)
    left = 1
    res = 0
    for l in range(left, right+1):
        cl = calc(l, x-(l-1)*A)
        if res < cl:
            res = cl
    return res
    
    
def calc(k, c):
    return pow(c//k+1, c%k)*pow(c//k, k-c%k)

N, A = map(int, readline().split())


ok = N
ng = 0
while abs(ok-ng)>1:
    med = (ok+ng)//2
    if check(med) >= N:
        ok = med
    else:
        ng = med
    
print(ok)