Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette. How many cigarettes can Peter have? Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k. For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have. Sample input4 3 10 3 100 5 Output for the sample input5 14 124 Original: Albert 2001 #include<iostream>using namespace std;int main(){ int n,k,num,left; while(cin>>n>>k) { num=n; left=n%k;//n butts并制成新烟后剩下的butts. n/=k; //用k butts做成新的n根烟 num+=n; //n根烟抽完又有n butts. n+=left; //新的n butts加上前面多出来的butts.(下同) while(n>=k) { num+=n/k; left=n%k; n/=k; n+=left; } cout<<num<<endl; } return 0;}

评论