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 in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

ll mypow(ll p, ll n){
    ll ret = 1;
    rep(n){
        ret *= p;
        if(10e12 / p + 1 < ret){
            return LLONG_MAX;
        }
    }
    return ret;
}

signed main(){
    ll N, A;
    cin >> N >> A;

    if(N<=3){
        cout << N << endl;
        return 0;
    }
    
    ll ans = N;
    reppp(k, 1, 40){
        ll ok = 100000000;
        ll ng = 1;
        while(abs(ok-ng) > 1){
            ll mid = (ok+ng)/2;
            ll tmp = mypow(mid, (ll)(k+1));
            if(tmp >= N || tmp == LLONG_MAX){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ll s1_num = 0;
        while(s1_num <= k && pow(ok-1, s1_num) * pow(ok, k+1-s1_num) >= N) s1_num++;
        if(s1_num < k+1 || pow(ok-1, s1_num) * pow(ok, k+1-s1_num) < N) s1_num--;
        //cout << k << " " << ok << " " << s1_num << endl;
        ans = min(ans, A*k + (ok-1)*s1_num + ok*(k+1-s1_num));
        //cout << A*k + (ok-1)*s1_num + ok*(k+1-s1_num) << endl;
    }
    cout << ans << endl;
    return 0;
}