/*
* 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. 第一章 认识jQuery

    jQuery是一个优秀的JavaScript库,它凭借简洁地语法和跨平台的兼容性,极大地简化了开发人员遍历HTML文档,操作DOM,处理事件,执行动画和开发Ajax操作. jQuery优势:1.轻量级 ...

  2. 多个html编辑器在同一页面加载

    http://127.0.0.1:3750/test.aspx 下载:ckfinder,ckeditor编辑器 <script type="text/javascript" ...

  3. linux运维常用命令

    1.linux启动过程 开启电源 --> BIOS开机自检 --> 引导程序lilo或grub--> 内核的引导(kernel boot)--> 执行init(rc.sysin ...

  4. ###《More Effective C++》- 异常

    More Effective C++ #@author: gr #@date: 2015-05-24 #@email: forgerui@gmail.com 九.利用destructors避免泄漏资源 ...

  5. 【html】【21】高级篇--搜索框

    下载: http://www.xwcms.net/js/bddm/25368.html 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

  6. dapper关联关系查询小测试

    测试实体类(表结构) public class User { public int user_id { get; set; } public string user_name { get; set; ...

  7. SQL日期操作及只获取日期的方法

    datepart()函数的使用                          * datepart()函数可以方便的取到时期中的各个部分*如日期:2006-07--02 18:15:36.513* ...

  8. Java架构必会几大技术点(转)

    关于学习架构,必须会的几点技术: 1. java反射技术 2. xml文件处理 3. properties属性文件处理 4. 线程安全机制 5. annocation注解 6. 设计模式 7. 代理机 ...

  9. CentOS7 firewall的使用

    # 查看区域 firewall-cmd --get-zones # 查看默认区域 firewall-cmd --get-default-zone # 给区域添加永久性服务 firewall-cmd - ...

  10. windows的路由例子

    一.不同网卡不同网关 wlan:192.168.100.1/24 wifi:192.168.8.1/24 1.如果想要特定的ip访问wifi网络 可以用 route add 1.2.3.4 mask ...