HihoCoder - 1498 Diligent Robots

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<cmath>
using namespace std;
#define ll long long
int main()
{
    ll m,q,ans=0,i,t;
    cin>>m>>q;
    ll sum = 999999999;
    while(1){
        if(pow(2,ans)>m)
            break;
        t=ans*q+m/(pow(2,ans));
        int num = m/pow(2,ans);
        if(m-pow(2,ans)*num!=0)
            t++;
        sum = min(t,sum);
        ans++;
    }
    cout<<sum<<endl;
}

 

posted @ 2017-07-06 16:33  冥想选手  阅读(187)  评论(0编辑  收藏  举报