时间限制:
10000ms
单点时限:
1000ms
内存限制:
256MB
-
10 1
样例输出
-
5
描述
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.
输入
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
输出
The minimum number of hours.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
#define ll long long
int main()
{
ll n,q,x,mi=0x3f3f3f3f;
cin>>n>>q;
x=sqrt(n);
for(ll i=0;i<=x;i++)
{
ll w=(ll)pow(2,i);
if(n%w==0)
w=n/w+i*q;
else
w=n/w+1+i*q;
mi=min(mi,w);
}
cout<<mi<<endl;
return 0;
}