欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1836B.Astrophysicists
Astrophysicists
In many, many years, far, far away, there will be a launch of the first flight to Mars. To celebrate the success, astrophysicists working on the project will be given bonuses of a total value of gold coins.
You have to distribute the money among the astrophysicists, and to make it easier, you have to assign bonuses in silver coins. Each gold coin is worth silver coins, so you have to distribute all silver coins among people.
Unfortunately, the company has some financial troubles right now. Therefore, instead of paying the number of silver coins written on the bonus, they decided to round this amount to the nearest integer number of gold coins.
The rounding procedure is as follows. If an astrophysicist has bonus equal to silver coins, and we denote , then:
- If , the astrophysicist receives silver coins;
- Otherwise, an astrophysicists receives silver coins.
Note that due to rounding, the total sum of actually paid money is not, in general, equal to silver coins. The operation denotes the remainder of the division of by . Sum of values before rounding has to be equal to silver coins, but some workers can be assigned silver coins.
You aim to distribute the bonuses so that the company saves as many silver coins due to rounding as possible. Please note that there is always a distribution in which the company spends no more than silver coins.
Input
In the first line of input, there is one integer () denoting the number of test cases.
Each of the following lines describes one test case and contains three integers , , (, , ) — respectively the number of astrophysicists in the company, total number of gold coins to assign and the number of silver coins that one gold coin corresponds to.
Output
In a separate line for each test case, output a single integer — the maximum number of silver coins that could be saved due to rounding.
Note
In the first test case, one of the optimal assignments could be the following:
- First person: silver coins: company pays , saves silver coins,
- Second person: silver coins: company pays , saves silver coins,
- Third person: silver coins: company pays , saves silver coins.
In the second test case, we could have the following assignment:
- First person: silver coins: company pays , spends extra silver coins,
- Second person: silver coins: company pays , saves silver coins.
If the bonuses are assigned to silver coins for both astrophysicists, then the company would have to pay an additional gold coin to cover the bonuses.
Samples
5
3 3 100
2 1 14
91 2 13
36 16 6
73 8 22
100
0
26
72
176
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |