#K43682. Potion Purchase Optimization
Potion Purchase Optimization
Potion Purchase Optimization
In this problem, Zoltar is on a quest to purchase a required amount of magical potion. The potion comes with a special bulk discount: when you pay for N liters, you receive an additional K liters free. That is, every discount cycle provides a total of \(N+K\) liters.
Your task is to help Zoltar determine the minimum number of liters he must pay for in order to obtain at least \(R\) liters of potion. Formally, given the required liters \(R\), the paid threshold \(N\), and the free liters \(K\), compute the minimum number of liters to be purchased such that the sum of the purchased liters and the free liters received during complete discount cycles meets or exceeds \(R\).
Note that if after using full discount cycles, the remaining liters needed is less than or equal to \(N\), then Zoltar only needs to purchase that remainder. Otherwise, he must make one additional full payment of \(N\) liters.
inputFormat
The input begins with a single integer (T) (the number of test cases). Each of the next (T) lines contains three space-separated integers: (R) (the required liters), (N) (the liters needed to trigger the discount), and (K) (the extra free liters received).
outputFormat
For each test case, output a single integer representing the minimum number of liters Zoltar must pay for in order to obtain at least (R) liters of potion. Each answer should be printed on its own line.## sample
1
10 3 1
8
</p>