CF1836B.Astrophysicists

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In many, many years, far, far away, there will be a launch of the first flight to Mars. To celebrate the success, nn astrophysicists working on the project will be given bonuses of a total value of kk 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 gg silver coins, so you have to distribute all kgk \cdot g silver coins among nn 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 xx silver coins, and we denote r=xmodgr = x \bmod g , then:

  • If rg2r \geq \lceil \frac{g}{2} \rceil , the astrophysicist receives x+(gr)x + (g - r) silver coins;
  • Otherwise, an astrophysicists receives xrx - r silver coins.

Note that due to rounding, the total sum of actually paid money is not, in general, equal to kgk \cdot g silver coins. The operation amodba \bmod b denotes the remainder of the division of aa by bb . Sum of values before rounding has to be equal to kgk \cdot g silver coins, but some workers can be assigned 00 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 kgk \cdot g silver coins.

输入格式

In the first line of input, there is one integer tt ( 1t1041 \leq t \leq 10^4 ) denoting the number of test cases.

Each of the following tt lines describes one test case and contains three integers nn , kk , gg ( 1n1091 \le n \le 10^9 , 0k1090 \le k \le 10^9 , 2g1092 \le g \le 10^9 ) — 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.

输出格式

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.

输入输出样例

  • 输入#1

    5
    3 3 100
    2 1 14
    91 2 13
    36 16 6
    73 8 22

    输出#1

    100
    0
    26
    72
    176

说明/提示

In the first test case, one of the optimal assignments could be the following:

  • First person: x=30x = 30 silver coins: company pays 00 , saves 3030 silver coins,
  • Second person: x=140x = 140 silver coins: company pays 100100 , saves 4040 silver coins,
  • Third person: x=130x = 130 silver coins: company pays 100100 , saves 3030 silver coins.

In the second test case, we could have the following assignment:

  • First person: x=8x = 8 silver coins: company pays 1414 , spends extra 66 silver coins,
  • Second person: x=6x = 6 silver coins: company pays 00 , saves 66 silver coins.

If the bonuses are assigned to 77 silver coins for both astrophysicists, then the company would have to pay an additional gold coin to cover the bonuses.

首页