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

Solution (Python):
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)

Solution (Python):

"""

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

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

    nm = int(N**(1/s))
    
    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)
"""

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
n,a = map(int,input().split())
if n == 1:
  print(1)
  exit()
if n <= a:
  print(n)
  exit()

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)

Solution (Python):
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)

Solution (Python):
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)

    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

    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

    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
    if cur<=0:
        return 1
    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 = min(40,now//(A+1))
        cur = ternarySearch(A,now,maxE)
        if N<=cur:
            r = now
        else:
            l = now


    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()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

"""
最適解の構造を観察する。
・最後のトドメ以外に関しては、「コストn+A払って倍率をn倍する」
・nとして現れるのは2種まで
・結局、nをx回、n+1をy回という形で、パラメータn,x,yで書ける（x\geq 1とする）
・最終枚数は、n^x(n+1)^y、これがN以上になって欲しい
・コストは、A(x+y-1) + nx + (n+1)y
・x+yを固定するごとに解く
"""

def F(K):
    
    
    n = int(N**(1/K))
    while (n-1)*n**(K-1) > N:
        n -= 1
    while n * (n+1)**(K-1) < N:
        n += 1
    
    for y in range(K):
        x = K-y
        if n**x * (n+1)**y >= N:
            break
    cost = A*(K-1) + n*x + (n+1)*y
    return cost

answer = min(F(K) for K in range(1,50))
print(answer)

Solution (Python):
import math


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


if __name__ == "__main__":
    main()

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, A = map(int, raw_input().split())
ans = 10 ** 18

for num in range(1, 65):
    p = int(N ** (1.0 / num))
    ls = [p] * num
    pos = 0
    while True:
        cnt = 1
        for p in ls:
            cnt *= p
        if cnt >= N:
            break
        ls[pos] += 1
        pos += 1
        pos %= num
    ans = min(ans, sum(ls) + A * (num - 1))
print ans

Solution (Python):

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)

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

ans = N

for k in range(50):
    left, right = 1, int(pow(N, 1/(k+1))) + 1
    while left + 1 < right:
        mid = (left + right) >> 1
        if mid ** (k+1) >= N:
            right = mid
        else:
            left = mid
    for i in range(k+1):
        if ((right - 1) ** i) * (right ** (k+1 - i)) >= N:
            ans = min(ans, A * k + i * (right - 1) + (k+1 - i) * right)
print(ans)

Solution (Python):



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, r = 0, 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, r = 0, 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

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

ans = N

for i in range(1, 50):
    ok = 10 ** 20
    ng = 0

    while ok - ng > 1:
        mid = (ok + ng) // 2
        prod = 1
        for j in range(i):
            prod *= (mid + j) // i
        if prod >= N:
            ok = mid
        else:
            ng = mid

    ans = min(ans, A * (i - 1) + ok)

print(ans)