No.915 Plus Or Multiple Operation
タグ : / 解いたユーザー数 197
作問者 :
tpyneriver
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もしくは右上の雲マークをクリックしてアカウントを作成してください。