time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

Little Lesha loves listening to music via his smartphone. But the smartphone doesn’t have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.

Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song’s duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.

Tell Lesha, for how many times he will start the song, including the very first start.

Input

The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).

Output

Print a single integer — the number of times the song will be restarted.

Examples

input

5 2 2

output

2

input

5 4 7

output

1

input

6 2 3

output

1

Note

In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.

In the second test, the song is almost downloaded, and Lesha will start it only once.

In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn’t restarted in this case.

【题目链接】:http://codeforces.com/contest/569/problem/A

【题解】



其实可以看成两辆车的追击问题;

一辆车A一开始在起点,另一辆B在S位置;

vA=1,vB=(q-1)/q;

则设经过了时间t

sa=t;

sb=s+(q-1)/q *t

令sa=sb

->t = q*s;

如果sb< t则sa又变回0,ans递增,此时s变成s+(q-1)/1*t;

然后重复上述步骤即可;

有点恶心。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int t,s,q; int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(t);rei(s);rei(q);
int now = s;
int bo = 0;
int ans = 1;
while (now<t)
{
//v download ->q/q-1
int tempt = q*s;
int d = (q-1)*(tempt/q);
now+=d;
if (now >=t) break;
ans++;
s = now;
}
printf("%d\n",ans);
return 0;
}

【30.49%】【codeforces 569A】Music的更多相关文章

  1. JAVA 基础编程练习题49 【程序 49 子串出现的个数】

    49 [程序 49 子串出现的个数] 题目:计算字符串中子串出现的次数 package cskaoyan; public class cskaoyan49 { public static void m ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【52.49%】【codeforces 556A】Case of the Zeros and Ones

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【30.93%】【codeforces 558E】A Simple Task

    time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  5. 【30.36%】【codeforces 740D】Alyona and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【30.23%】【codeforces 552C】Vanya and Scales

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【59.49%】【codeforces 554B】Ohana Cleans Up

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【30.43%】【codeforces 746C】Tram

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【codeforces 776E】The Holmes Children

    [题目链接]:http://codeforces.com/contest/776/problem/E [题意] f(n)是小于n的不同整数对(x,y)这里x+y==n且gcd(x,y)==1的个数; ...

随机推荐

  1. PHP和JSON

    PHP和JSON 一.总结 1.php中json的使用方法:php中json的使用超级简单啦,主要是两个函数json_encode(编码)和json_decode(解码),像md5加密 2.json的 ...

  2. Unity5中的粒子缩放(附测试源码)

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/49363241 作者:car ...

  3. 【Codeforces Round #429 (Div. 2) A】Generous Kefa

    [Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...

  4. openstack之虚拟机创建流程分析

    这篇博文静静的呆在草稿箱大半年了.假设不是由于某些原因被问到,以及由于忽略它而导致的损失,否则我也不知道什么时候会将它完毕.感谢这段时间经历的挫折,让我知道不足.希望你能给我更大的决心! 本文试图具体 ...

  5. ajax中的POST和GET传值

    ajax中的POST和GET传值 转自:http://www.cnblogs.com/jtome/archive/2008/12/04/1347864.html Ajax中我们经常用到get和post ...

  6. 15、python学习手册之:列表和字典

    1.列表属于可变序列,支持在原处的修改 2.在标准python解锁器内部,列表就是C数组而不是链接结构 3.内置函数map对序列中的各项应用一个函数并把结果收集到一个新的列表中 eg:list(map ...

  7. 二、MongoDB基础知识

    1.文档是MongoDB的核心概念.文档就是键值对的一个有序集{'msg':'hello','foo':3}.类似于python中的有序字典. 需要注意的是: #1.文档中的键/值对是有序的. #2. ...

  8. 洛谷 P1644 跳马问题

    P1644 跳马问题 题目背景 在爱与愁的故事第一弹第三章出来前先练练四道基本的回溯/搜索题吧…… 题目描述 中国象棋半张棋盘如图1所示.马自左下角(0,0)向右上角(m,n)跳.规定只能往右跳,不准 ...

  9. Android多线程研究(6)——多线程之间数据隔离

    在上一篇<Android多线程研究(5)--线程之间共享数据>中对线程之间的数据共享进行了学习和研究,这一篇我们来看看怎样解决多个线程之间的数据隔离问题,什么是数据隔离呢?比方说我们如今开 ...

  10. 开源企业IM-免费企业即时通讯-ENTBOOST V2014.177 Windows版本号正式公布

    ENTBOOST,VERSION 2014.177 LINUX 版本号公布.主要添加Android安卓手机开发接口.企业IM接口,JQUERY开发接口,PCclient部分BUG修正: 下版本号更新时 ...