/*
* BurningMidnightOil.cpp
*
* Created on: 2013-10-12
* Author: wangzhu
*/ /**
* 每次至少写多少行代码ret:
* 1)、当n<=k时,肯定是ret = n;
* 2)、当n > k时,则 ret>=k&ret <= n,故只需要按二分的思路将其查找一下,就可以,
* 对于每一个可能的值进行计算可以书写的代码行,之后继续,最后得到的结果就是答案
*/
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
LL calc(int k, int v) {
//数据容易溢出
LL sum = v, kk = k;
while (v / kk) {
sum += v / kk;
kk *= k;
}
return sum;
}
int binarySearch(int n, int k) {
LL left = k, right = n, mid = -;
while (left <= right) {
mid = left + (right - left) / ;
if (n <= calc(k, mid)) {
right = mid - ;
} else {
left = mid + ;
}
}
return (int) left;
}
int main() {
freopen("data.in", "r", stdin);
int n, k;
while (~scanf("%d%d", &n, &k)) {
if(n <= k) {
printf("%d\n",n);
continue;
} printf("%d\n", binarySearch(n, k));
}
return ;
}

Codeforces Burning Midnight Oil的更多相关文章

  1. B - Burning Midnight Oil CodeForces - 165B

    One day a highly important task was commissioned to Vasya — writing a program in a night. The progra ...

  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. CodeForces 508C Anya and Ghosts

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

  6. 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 ...

  7. Codeforces 767B. The Queue 模拟题

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

  8. 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. ...

  9. codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]

    就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...

随机推荐

  1. PHP之数组函数归类

    数组之所以强大,除了本身声明.存储方式灵活,它还有坚强后盾:一系列功能各异的数组处理函数.就像一只军队,除了领队将军本身能征善战,指挥英明之外,还有一群不怕死.忠实于他的士兵,这样才能显得整体的强大. ...

  2. namenode无法自动切换的问题

    主namenode 为standly状态,备namenode为active,kill备namenode,主namenode能正常切换为active.但是主namenode为active,备nameno ...

  3. Kettle ETL 来进行mysql 数据同步——试验环境搭建(表中无索引,无约束,无外键连接的情况)

    今天试验了如何在Kettle的图形界面(Spoon)下面来整合来mysql 数据库中位于不同数据库中的数据表中的数据. 试验用的数据表是customers: 第三方的数据集下载地址是:http://w ...

  4. 牛客_剑指offer_重建二叉树,再后续遍历_递归思想_分两端

       总结:    重建二叉树:其实就是根据前序和中序重建得到二叉树,得到后续,只要输出那边设置输出顺序即可 [编程题]重建二叉树 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的 ...

  5. python 笔记(一)

    1.Python优点 简单,优雅,明确 强大的模块第三方库 易移植 面向对角 可扩展 2.缺点 代码不能加密 执行速度慢 3.变量定义 第一个字母必须是字母表中的大小写,或下划线.不能以数字为开头. ...

  6. Ext.Net学习笔记15:Ext.Net GridPanel 汇总(Summary)用法

    Ext.Net学习笔记15:Ext.Net GridPanel 汇总(Summary)用法 Summary的用法和Group一样简单,分为两步: 启用Summary功能 在Feature标签内,添加如 ...

  7. 批处理 Mysql Findstr

    @set Dump_IP=localhost @set User_Name=root @set Password=1234 @set curPath=%~dp0 mysql -h %Dump_IP% ...

  8. iOS RunTime的简单使用

    1.根据指定规则根据runtime进行页面选择跳转 背景:要根据后台返回的数据 进行选择要跳转到哪一个ViewController // 这个规则肯定事先跟服务端沟通好,跳转对应的界面需要对应的参数 ...

  9. IOS 高级开发 KVC(一)

    熟练使用KVC 可以再开发过程中可以给我们带来巨大的好处,尤其是在json 转模型的时候,KVC让程序员摆脱了繁琐无营养的代码堆积.减少代码量就是减少出错的概率.KVC 用起来很灵活,这种灵活的基础是 ...

  10. C#break、continue、return、goto

    1.break break语句会使运行的程序立即退出包含在其中的最内层循环(结束此次循环且结束该循环控制体)或者switch语句 ; ; j < ; j++) { i++; )break; Co ...