Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them
one by one keeping all the butts. Out of k > 1 butts he can roll a new
cigarette.
Now,do you know how many cigarettes can Tom has?
3 4 3 10 3 100 5
5 14 124
#include<iostream>
using namespace std;
int
main(){
int test,m,n,i,k,s;
cin>>test;
while(test--){
int
s;
cin>>m>>n;
s=m;
i=m;
while(i>=n){
s=s+i/n; //可换的烟
i=i/n+i%n; //现有的烟蒂
}
cout<<s<<endl;
}
return 0;
}
原文:http://www.cnblogs.com/dreamgoing/p/3587291.html