10346-peter ' s smokes
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1287
Peter has n cigarettes. He smokes them one by one keeping all the butts. Out OFK > 1 butts He can roll a new cigarette.
How many cigarettes can Peter have?
Input
The Input is a sequence of lines. Each line contains two integer numbers giving the values ofn and K. The ' input is terminated by ' file.
Output
For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter CA N have.
Sample Input
4 3
10 3
100 5
Sample Output
5
14
124
Complete code:
/*0.018s*/
#include <cstdio>
int main ()
{
int n, k, I;
while (~SCANF ("%d%d", &n, &k))
{for
(i = n; i >= k; i = i% k + i/k) n + = i/k;
printf ("%d\n", n);
}
return 0;
}
Author: csdn Blog Synapse7
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/