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<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>
#include<set>
#include<queue>

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

using namespace std;

/*
bool taberuBeki(int speed, int cookie, int n, int a, int i, vector<int>& iByouGoKuu){
	bool flag = false;
	if(cookie <= speed)
		return false;
	else{
		int tabenaiToki = (n - cookie - 1) / speed + 1;
		int imaKuu = iByouGoKuu[i % a];
		iByouGoKuu[i % a] = a + a + (n - 1) / (speed * a + cookie) + 1;
	}
	return flag;
}*/

int fdiv(int n, int a){
	if(n % a == 0)
		return n / a;
	else
		return n / a + 1;
}

int main(){
	int n, a; cin >> n >> a;
	int cookie = 2;
	int speed = 1;
	int tabeTeru = 0;
	/*
	rep(i,a){
		if(i*speed + cookie <= speed)
			iByouGokuu.push_back(n + 100);
		else{
			iByouGokuu.push_back(i + a + (n - 1) / (speed * i + cookie) + 1);
		}
	}*/
	int i = 2;
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}
	else if(n == 2){
		cout << 2 << endl;
		return 0;
	}

	while(1){
		int catchUp = fdiv((1 + a) * cookie, cookie - speed);
		int noEat = fdiv(n - cookie, speed);
		if(noEat <= catchUp){
			cout << i + noEat << endl;
			return 0;
		}
		int itr = 0;
		int nowmax = (catchUp - a)*cookie;
		rep(j,catchUp){
			int atCatch = (catchUp - a - j) * (cookie + speed * j);
			if(atCatch >= nowmax){
				itr = j;
				nowmax = atCatch;
			}
		}
		i += catchUp;
		speed = itr*speed + cookie;
		cookie = nowmax;
		/*
		if(cookie >= n){
			cout << i << endl;
			return 0;
		}*/
		/*
		int noEat = fdiv(n - cookie, speed);
		int nowmin = n + 100;
		int itr = -1;
		rep(j,a + 1){
			int jAfter = fdiv(n, cookie + speed*j) + j + a;
			if(nowmin > jAfter){
				nowmin = jAfter;
				itr = j;
			}
		}
		if(noEat <= nowmin){
			cout <<  i + noEat << endl;
			return 0;
		}
		else{
			speed = cookie + itr*speed;
			i += a + itr + 2;
			cookie = 2*speed;
			if(cookie >= n){
				cout << i << endl;
				return 0;
			}
		}*/
	}
}