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 <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

long long N, A;

std::unordered_map<long long, long long> mp;

template<class Fn> long long ternary_search(long long L, long long R, Fn func) {
    long long seg = (R - L) / 3;
    if (seg <= 1) {
        long long ret = L;
        long long val = func(L);
        for (long long i = L + 1; i <= R; i++) {
            long long tmp = func(i);
            if (tmp < val) {
                ret = i;
                val = tmp;
            }
        }
        return ret;
    }

    long long t1 = L + seg;
    long long t2 = L + seg * 2;

    if (func(t1) <= func(t2)) {
        return ternary_search(L, t2, func);
    } else {
        return ternary_search(t1, R, func);
    }
}

long long calc(long long V) {
    //std::cout << "calc:" << V << std::endl;
    if (mp.find(V) != mp.end()) {
        return mp[V];
    }
    if (V <= 4) {
        mp[V] = V;
        return V;
    }

    long long ret = V;

    long long best = ternary_search(2, V/2 + 1,
        [&](const long long i) {
            long long tmp = V % i == 0 ? V / i : V / i + 1;
            return calc(i) + A + tmp;
        }
    );

    long long tmp = V % best == 0 ? V / best : V / best + 1;
    ret = std::min(ret, calc(best) + A + tmp);

    /*
    for (int i = 2; i <= V / 2 + 1; i++) {
        long long tmp = V % i == 0 ? V / i : V / i + 1;
        ret = std::min(ret, calc(tmp) + A + i);
    }
    */

    mp[V] = ret;
    return ret;
}

int main(int argc, char **argv) {
    std::cin >> N >> A;

    std::cout << calc(N) << std::endl;

    return 0;
}