Luo Gu P1150 Peter smoke

Title Description

Peter has n cigarette, each finished smoking a cigarette he put the cigarette butts saved, k (k> 1) cigarette butts can change a new cigarette, then how much Peter eventually be able to breathe cigarette it?

Input Format

Each test line contains two integers n-, K (. 1 <n-, k≤10 ^. 8 ).

Output Format

For each test, including the output line represents an integer the number of the final smoke.

Sample input and output

Input # 1
4 3
Output # 1
5
Input # 2
10 3
Output # 2
14

Description / Tips

1<n,k≤10^8

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int ans=0,in=0,check=0,head=0;
 6     cin>>in>>check;
 7     head=in;
 8     ans=in;
 9     while(1){
10         if(head>=check){
11             ans=ans+floor(head/check);
12             head=head%check+head/check;
13         }else{
14             cout<<ans;
15             return 0;
16         }
17         
18     }
19 }

 

Guess you like

Origin www.cnblogs.com/anbujingying/p/11293673.html