問題一覧 > 通常問題

No.915 Plus Or Multiple Operation

レベル : / AI推定難易度 : 1350 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 197
作問者 : ningenMe / テスター : tpyneriver
お気に入りにしたユーザー ProblemId : 3389 / 自分の提出
問題文最終更新日: 2019-10-26 00:21:27
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 229 (順位表) の他の問題:

Problem Statement

Kuru-kun initially has $0$ cookies. He wants to have exactly $A$ cookies.
There are the following $2$ types of operations for increasing the number of cookies.

 ・Pay $B$ yen. Choose one number $i$ that is at least $1$ and less than $C$, and buy cookies. The number of cookies increases by $i$.
 ・Pay $B$ yen. You obtain permission to smash the cookies, and the number of cookies is multiplied by $C$.

The above operations can be performed in any order and any number of times.
Kuru-kun wants to have exactly $A$ cookies using as little money as possible. Find the minimum cost.
If it is impossible to have exactly $A$ cookies, output $-1$.

The input is given as $Q$ queries, so find the answer for each of them.

Input

$Q$
$A_1\ B_1\ C_1$
$\vdots$
$A_Q\ B_Q\ C_Q$

All inputs are integers.
$1 \le Q \le 20$
$1 \le A_i,B_i,C_i \le 10^9\ (1 \le i \le Q)$

Output

Output $Q$ lines.
Answer each query, with $A_i,B_i,C_i$ being $A,B,C$ in the problem statement, respectively.
Print a newline after each query.

Sample

Sample 1
Input
1
7 1 3
Output
3

By transitioning as shown below, you can reach $7$ cookies for $1×3=3$ yen.
$\ 0$ (initial state)
→ $(+2)\ 2\ $
→ $(×3)\ 6\ $
→ $(+1)\ 7\ $

Sample 2
Input
1
133 2 5
Output
12

By transitioning as shown below, you can reach $133$ cookies for $2×6=12$ yen.
$\ 0$ (initial state)
→ $(+1)\ 1\ $
→ $(×5)\ 5\ $
→ $(×5)\ 25\ $
→ $(×5)\ 125\ $
→ $(+4)\ 129\ $
→ $(+4)\ 133\ $

Sample 3
Input
2
12345789 987654321 57
12 2 3
Output
7901234568
6

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。