题目描述
Problem Background
Iris and Beryl are playing a guessing game.
Problem Description
The game proceeds as follows: Given a positive integer \( n \), Iris chooses a number \( m \) from the set \( S = \{1, 2, \ldots, n\} \).
Then, Iris must truthfully answer several questions from Beryl, which are of the form: "Is \( m \) an element of the set \( A \)?", where \( A \subseteq S \).
If Iris answers "yes", Beryl must give Iris \( a \) dollars; otherwise, Beryl must give Iris \( b \) dollars. (The data guarantees \( a > b \))
So, what is the minimum amount of money Beryl needs to prepare to ensure they can determine the number in Iris's mind?
Input Format
The first line contains two positive integers \( a \) and \( b \), and the number of test cases \( t \).
The next \( t \) lines each contain a given positive integer \( n \), as described above.
Output Format
\( t \) lines, each indicating the minimum amount of money Beryl needs to prepare for each test case.
Sample Input and Output
Sample Input #1
2 1 2
3
6
Sample Output #1
3
5
Sample Input #2
5 3 1
3
Sample Output #2
8
Notes
Explanation of the first set of data in Sample 1:
Beryl first asks about the set \(\{1\}\). If the answer is "yes", then the number chosen by Iris is \(1\), and Beryl needs \(2\) dollars. If the answer is "no", then Beryl asks about the set \(\{2\}\). In the worst-case scenario, Beryl needs to spend another \(2\) dollars, totaling \(3\) dollars. Therefore, the answer is \(3\) dollars.
Data Range:
| Test Case Number | \( n \) | \( t \) | \( a \), \( b \) |
|---|---|---|---|
| 1 | \(\leq 20\) | \(\leq 10\) | \(\leq 20\) |
| 2 | \(\leq 20\) | \(\leq 10\) | \(\leq 20\) |
| 3 | \(\leq 2000\) | \(\leq 100\) | \(\leq 500\) |
| 4 | \(\leq 2000\) | \(\leq 100\) | \(\leq 500\) |
| 5 | \(\leq 2000\) | \(\leq 100\) | \(\leq 500\) |
| 6 | \(\leq 2000\) | \(\leq 100\) | \(\leq 500\) |
| 7 | \(\leq 2000\) | \(\leq 100\) | \(\leq 500\) |
| 8 | \(\leq 10^{18}\) | \(\leq 200\) | \( a = 2 \), \( b = 1 \) |
| 9 | \(\leq 10^{18}\) | \(\leq 200\) | \( a = 2 \), \( b = 1 \) |
| 10 | \(\leq 10^{18}\) | \(\leq 200\) | \( a = 2 \), \( b = 1 \) |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分