正文

Peter's smokes2007-02-25 11:05:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/xiaoxiaofeng/23458.html

分享到:

  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;}

阅读(62) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册