ORIGIN

HDU-1555 How many days?

ACM 1 mins189 words

How many days?

The 8600’s mobile phone consumes 1 yuan per day, and every K yuan spent will receive 1 yuan. At the beginning, 8600 has M yuan. How many days can I use?

Input

The input includes multiple test instances. Each test instance includes two integers M, k, (2 <= k <= M <= 1000). M = 0, k = 0 represents the end of the input.

Output

An integer is output for each test instance, which indicates the number of days that M yuan can be used.

Sample Input

1
2
3
2 2
4 3
0 0

Sample Output

1
2
3
5

Analysis

This is just stimulation. At first I think the answer was $m + m \div k$ . However, I didn’t think of that there may be given more than k days more.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<bits/stdc++.h>

using namespace std;

int main() {
int m, k;
while(cin >> m >> k, m, k) {
int count = 0, ik = 0;
while(m) {
m --;
ik ++;
if(ik % k == 0) {
m += 1;
ik = 0;
}
count ++;
}
cout << count << endl;
}
return 0;
}
TOP
COMMENT
  • ABOUT
  • |
o_oyao
  The Jigsaw puzzle is incomplete with even one missing piece. And I want to be the last piece to make the puzzle complete.
Like my post?
Default QR Code
made with ❤️ by o_oyao
©o_oyao 2019-2024

|