atcoder#CODEFESTIVAL2016FINALE. Cookies

Cookies

Score : 10001000 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 xx 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 xx. Note that a cookie always needs to be baked for 11 second, that is, he cannot bake a cookie in 1/x1/x seconds when x>1x > 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 AA seconds to eat the cookies regardless of how many, during which no cookies can be baked.

He wants to give NN cookies to Grandma. Find the shortest time needed to produce at least NN cookies not yet eaten.

Constraints

  • 1N10121 \leq N \leq 10^{12}
  • 0A10120 \leq A \leq 10^{12}
  • AA is an integer.

Partial Score

  • 500500 points will be awarded for passing the test set satisfying N106N \leq 10^6 and A106A \leq 10^6.
  • Additional 500500 points will be awarded for passing the test set without additional constraints.

Input

The input is given from Standard Input in the following format:

NN AA

Output

Print the shortest time needed to produce at least NN cookies not yet eaten.

8 1
7

It is possible to produce 88 cookies in 77 seconds, as follows:

  • After 11 second: 11 cookie is done.
  • After 22 seconds: 11 more cookie is done, totaling 22. Now, Rng starts eating those 22 cookies.
  • After 33 seconds: He finishes eating the cookies, and he can now bake 22 cookies per second.
  • After 44 seconds: 22 cookies are done.
  • After 55 seconds: 22 more cookies are done, totaling 44.
  • After 66 seconds: 22 more cookies are done, totaling 66.
  • After 77 seconds: 22 more cookies are done, totaling 88.
1000000000000 1000000000000
1000000000000