1 /*描述
 2 Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them
 3 one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette. 
 4 Now,do you know how many cigarettes can Tom has?
 5 
 6 输入
 7 First input is a single line,it's n and stands for there are n testdata.then there are n lines ,
 8 each line contains two integer numbers giving the values of n and k.
 9 输出
10 For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have.
11 样例输入
12 3
13 4 3
14 10 3
15 100 5
16 样例输出
17 5
18 14
19 124*/
20 #include<stdio.h>
21 int main()
22 {
23     int n;
24     scanf("%d",&n);
25     while( n-- )
26     {
27         int f(int a,int b);
28         int l , k;
29         scanf("%d%d",&l,&k);
30         printf("%d\n",f(l,k));
31     }
32     return 0;
33 }
34 int f(int a,int b)
35 {
36     int sum = a, x , y ;
37     while(a >= b)
38     {
39         sum = a/b + sum;
40         y = a % b;
41         x = a / b;
42         a = y + x;
43     }
44     return sum;
45 }
46