## Problem: Halloween party

Little Bob loves chocolates and goes to the store with a \$N bill with \$C being the price of each chocolate. In addition, the store offers a discount: for every M wrappers he gives the store, he’ll get one chocolate for free. How many chocolates does Bob get to eat?

Input Format:
The first line contains the number of test cases T (<=1000).
Each of the next T lines contains three integers N, C and M

Output Format:
Print the total number of chocolates Bob eats.

Constraints:
2 <= N <= 100000
1 <= C <= N
2 <= M <= N

Sample input

``````3
10 2 5
12 4 4
6 2 2
``````

Sample Output

``````6
3
5
``````

Explanation
In the first case, he can buy 5 chocolates with \$10 and exchange the 5 wrappers to get one more chocolate thus making the total number of chocolates he can eat as 6

In the second case, he can buy 3 chocolates for \$12. However, it takes 4 wrappers to get one more chocolate. He can’t avail the offer and hence the total number of chocolates remains 3.

In the third case, he can buy 3 chocolates for \$6. Now he can give 2 of this 3 wrappers and get 1 chocolate. Again, he can use his 1 unused wrapper and 1 wrapper of new chocolate to get one more chocolate. Total is 5.

This is my code:

#include <stdio.h>

long _Halloween_Party(long _n);

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

/*n is the amount of test cases*/
int _n;

/*array a to store input value, b to store result to print*/
long _a[1000],_b[1000],_i;
scanf(“%d”,&_n);
for(_i=0;_i<_n;++_i)
scanf(“%ld”,&_a[_i]);
for(_i=0;_i<_n;++_i){
_b[_i]=_Halloween_Party(_a[_i]);
}
for(_i=0;_i<_n;++_i){
printf(“%ld”,_b[_i]);
if(_i!=_n-1)
printf(“\n”);
}
return 0;
}

/*Write down some case in paper, and you’ll find out your own way to solve this problem*/

/*This is my method*/

long _Halloween_Party(long _n){
long _i,_Count=0;
long _Sum=0,_Raise=1;
for(_i=1;_i<_n;++_i){
if(_Count==2){
_Raise+=1;
_Count=0;
}
_Sum+=_Raise;
_Count+=1;
}
return _Sum;
}