One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as  lines, drinks another cup of tea, then he writes  lines and so on: , ...

The expression  is regarded as the integral part from dividing number a by number b.

The moment the current value  equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.

Vasya is wondering, what minimum allowable value v can take to let him write not less than n lines of code before he falls asleep.

Input

The input consists of two integers n and k, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1 ≤ n ≤ 109, 2 ≤ k ≤ 10.

Output

Print the only integer — the minimum value of v that lets Vasya write the program in one night.

Examples

Input
7 2
Output
4
Input
59 9
Output
54

Note

In the first sample the answer is v = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.

In the second sample the answer is v = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than n = 59.

题解:找到一个合适的值V,

【一天,一个非常重要的任务被委托给Vasya--在一个晚上写一个程序。该程序由n行代码组成。Vasya已经耗尽,所以,他的作品就像是:第一,他写道v行代码,喝一杯茶,然后他尽可能多写为线,饮料一杯茶,然后他写道线等:, ...

该表达式被视为从数字a除以数字b组成的组成部分。

当前值等于0 的那一刻,Vasya立即睡着了,他只在早上才醒来,当时程序应该已经完成​​。

Vasya很纳闷,有什么最小允许值v可以让他写不低于比ň行代码,他睡着了。】

【题析】:需要用二分查找

 #include<bits/stdc++.h>
using namespace std; int main() {
long long n;
int m;
scanf("%lld %d",&n,&m);
long long v;
int flag = ;
long long vv;
long long mid;
long long left = ;
long long right = n;
long long ans = n;
while(left <= right) {
mid = (left + right) / ;
//printf("%lld %lld %lld\n",left,right,mid);
long long sum = mid;
int count = ;
long long v = m;
int vv = mid/v;
while(vv){
sum += vv;
count++;
v = v*m;
vv = mid/v;
}
if(flag == ) break;
if(sum >= n) { ans = min(ans,mid);
right = mid - ;
ans = min(ans,mid);
} else {
left = mid + ;
}
}
printf("%lld\n",ans);
return ;
}

B - Burning Midnight Oil CodeForces - 165B的更多相关文章

  1. Codeforces Burning Midnight Oil

    /* * BurningMidnightOil.cpp * * Created on: 2013-10-12 * Author: wangzhu */ /** * 每次至少写多少行代码ret: * 1 ...

  2. 2016.09.14,英语,《Using English at Work》全书笔记

    半个月时间,听完了ESLPod出品的<Using English at Work>,笔记和自己听的时候的备注列在下面.准备把每个语音里的快速阅读部分截取出来,放在手机里反复听. 下一阶段把 ...

  3. English idioms

    a hot potato : speak of an issue(mostly current) which many people are talking about and which is us ...

  4. 英语口语练习系列-C14-常用片语

    句子 1. Some ads are extremely persuasive and we find we buy products we don't really need. 有一些广告非常有说服 ...

  5. CSU训练分类

    √√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...

  6. CodeForces 508C Anya and Ghosts

     Anya and Ghosts Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  7. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  9. Codeforces Beta Round #14 (Div. 2) A. Letter 水题

    A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...

随机推荐

  1. redis 实际应用中的缓存作用(转)

    有人说互联网用户是用脚投票的,这句话其实也从侧面说明了,用户体验是多么的重要:这就要求在软件架构设计时,不但要注重可靠性.安全性.可扩展性以及可维护性等等的一些指标,更要注重用户的体验,用户体验分很多 ...

  2. Tomcat+Servlet登录页面实例

    概念   Tomcat server是一个免费的开放源码的Web 应用server,属于轻量级应用server,在中小型系统和并发訪问用户不是非常多的场合下被普遍使用,是开发和调试JSP 程序的首选. ...

  3. Android Studio 经常使用手冊

    经常使用小操作 单词选择 显示近期操作 改动的文件 文件查找 操作记录 移动行 查找方法调用处 方法的跟进 显示方法的參数 行的高速操作 多行操作 高速补全完毕 代码提示 变量的高速操作 代码折叠 预 ...

  4. 解决java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException

    解决: 工程目录.settings\org.eclipse.wst.common.project.facet.core.xml文件中jst.web的version降低到2.5 <?xml ver ...

  5. STM32 USB复合设备编写

    目的 完成一个CDC + MSC的复合USB设备 可以方便在CDC,MSC,复合设备三者间切换 可移植性强 预备知识 cube中USB只有两个入口. main函数中的MX_USB_DEVICE_Ini ...

  6. [LeetCode][Java] Remove Duplicates from Sorted List II

    题意: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct  ...

  7. 深度学习笔记之CNN(卷积神经网络)基础

    不多说,直接上干货! 卷积神经网络(ConvolutionalNeural Networks,简称CNN)提出于20世纪60年代,由Hubel和Wiesel在研究猫脑皮层中用于局部敏感和方向选择的神经 ...

  8. shuf乱序排列

    如何从文件中随即选取1000行内容呢?我们可以使用shuf命令 shuf [ 其中,shuf会读取file中的内容,并生成乱序的排列,进而使用head命令,取出前1000行

  9. 反射学习总结 --为理解SpringMVC底层做准备

    反射是什么? 通俗理解 - 照X光. java:一个类在反射面前就像照X光,清清楚楚明明白白. 应用:我们的ide中,能够"."一下就知道类中的所有方法就是通过反射实现的. XML ...

  10. Android 4.4.2 动态加入JNI库方法记录 (二 app应用层)

    欢迎转载,务必注明出处:http://blog.csdn.net/wang_shuai_ww/article/details/44458553 源代码下载地址:http://download.csdn ...