ecjtu-summer training #2 D

来源:互联网 发布:elementary 安装软件 编辑:程序博客网 时间:2024/06/06 00:36

There are N jobs to be finished. It takes a robot 1 hour to finish one job.

At the beginning you have only one robot. Luckily a robot may build more robots identical to itself. It takes a robot Q hours to build another robot.  

So what is the minimum number of hours to finish N jobs?

Note two or more robots working on the same job or building the same robot won't accelerate the progress.

Input

The first line contains 2 integers, N and Q.  

For 70% of the data, 1 <= N <= 1000000  

For 100% of the data, 1 <= N <= 1000000000000, 1 <= Q <= 1000

Output

The minimum number of hours.

Sample Input
10 1
Sample Output

5


//签到
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long long N,Q,t,i,j;
    while(cin>>N>>Q){
        t=2,i=1;
        j=N;
        while(t<N){
            j=min(j,i*Q+N/t+(N%t==0?0:1));
            t=t*2;
            i++;
        }
        cout<<j<<endl;
    }
    return 0;
}