codeforces 569A__Music

A. Music
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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 ≤ 1041 ≤ S < T ≤ 105).

Output

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

Sample test(s)
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.


題意:一首歌一共有T秒,s表示第一次下載的秒數,q表示每q秒可以下載(q-1)秒這首歌,第一次下載結束後,每次播放的同時會下載。求一共從頭開始播放的次數。

題解:一道很好的想法題,每當播放到之前的未download處時,由於播放的同時也在下載,所以總會再次下載了一些,理論上會無限循環播放和下載,但總會有個極限,可以記爲S(當前可播放的時間)。
S=s+s*(q-1)/q+s*(q-1)/q*(q-1)/q+...。運用等比數列求和可以得知當n->+∞時,S=s*q;
當播放到第i次的時候S=s*(q^i)。使S>=T即可。
代碼如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int T,s,q;
    while(~scanf("%d%d%d",&T,&s,&q)) {
        int S=s,i=0;
        while(S<T) {
            S=S*q;
            i++;
        }
        printf("%d\n",i);
    }
    return 0;
}


發佈了51 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章