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 <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const ll INF = 1001001001001001ll;

signed main()
{
    ll n, a;
    cin >> n >> a;
    
    if(a <= 1000000){
        vi dp(1000000 * 45);
        rep(t, dp.size()) dp[t] = t;
        
        int mae = 1;
        
        rep(t, dp.size()){
            reps(s, mae, t){
                ll tmp = dp[s] * (t-s-a);
                if(tmp > dp[t]){
                    mae = s;
                    dp[t] = tmp;
                }
            }
            
            if(dp[t] >= n){
                cout << t << endl;
                return 0;
            }
            if(t==100) break;
        }
    }
    else{
        vi dp(2000000, INF);
        dp[1] = 0;
        
        reps(i, 1, dp.size()){
            for(int j=i*2; j<dp.size(); j+=i){
                dp[j] = min(dp[j], dp[i] + (i/j) + a);
            }
        }
        
        ll ans = INF;
        reps(i, 1, dp.size()){
            ans = min(ans, dp[i] + (n+i-1)/i);
        }
        
        cout << ans << endl;
    }
}