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=,i,t;
cin>>m>>q;
ll sum = ;
while(){
if(pow(,ans)>m)
break;
t=ans*q+m/(pow(,ans));
int num = m/pow(,ans);
if(m-pow(,ans)*num!=)
t++;
sum = min(t,sum);
ans++;
}
cout<<sum<<endl;
}

最新文章

  1. 分析器错误消息: 未能加载类型“Automation.Web.MvcApplication”。
  2. C# LINQ
  3. 修复一个吉日嘎拉MSSQL数据库版中的分页存储过程bug
  4. Linux命令lsb_release:查看当前系统的发行版信息
  5. Consul Template的简单使用
  6. JS 对象属性相关--检查属性、枚举属性等
  7. 原生的AJAX写法,可以直接复制过来套用
  8. C++定义全局变量/常量几种方法的区别
  9. 人生的抉择—aspx、ashx、asmx文件处理请求效率比较
  10. 分布式 ES 操作流程解析
  11. POJ 2057 The Lost House
  12. 《Windows驱动开发技术详解》之Windows内核函数
  13. git仓库搭建及客户端使用
  14. java笔记:排错5:误删maven target:恢复不了,怎么再生成
  15. Hbase学习03
  16. 【洛谷p1605】迷宫
  17. php英语单词大全95
  18. C#编码、解码与ASP.NET编码解码对应函数
  19. day11 作用域
  20. spring cloud配置中心属性加密处理

热门文章

  1. RHEL7VIM编辑器
  2. Intel x86_64 Architecture Background 3
  3. CentOS7下安装Docker-Compose操作记录
  4. 分布式监控系统Zabbix-3.0.3-完整安装记录(3)-监控nginx,php,memcache,Low-level discovery磁盘IO
  5. GCD实现同步方法
  6. 关键字搜索:jQuery过滤器插件fastLiveFilter||显示结果条数
  7. Linux内核分析 读书笔记 (第四章)
  8. Opentsdb 启动显示配置文件不存在
  9. oracle alter
  10. 结构化分析(SA)