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<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const LL INF = 1e17;
LL N;
LL A;
LL dp[2145141];
LL imos[2145142];
int ar[2145141];

int main() {
  scanf("%lld%lld", &N, &A);

  const int LIM = 2000000;
  fill(dp, dp+LIM, INF);

  dp[1] = 1;
  reps(i, 1, LIM) {
    LL t = dp[i];
    if (i > 1) t += A+1;
    for (LL j=i+i; j<LIM; j+=i) {
      ++t;
      if (MN(dp[j], t)) ar[j] = i;
    }
  }

  imos[LIM] = INF;
  rrep(i, LIM) {
    imos[i] = min(imos[i+1], dp[i]);
  }

  LL ans = N;
  reps(i, 2, LIM) {
    LL k = N/i + (N%i != 0);
    if (k < LIM) MN(ans, imos[k] + A + dp[i]);
    else {
      MN(ans, dp[i] + A + k);
    }
  }
  printf("%lld\n", ans);
}