luogu#P4862. 猜数

猜数

Background

Iris and Beryl are playing a number guessing game.

Problem Description

The game works as follows: given a positive integer nn, Iris chooses a number mm from S={1,2,...,n}S=\{1,2,...,n\}.

Then, Iris must answer Beryl’s questions truthfully. Each question is of the form: “Is mm an element of set AA?” where ASA\subseteq S.
If Iris answers “Yes”, then Beryl must give Iris aa yuan; otherwise, Beryl must give Iris bb yuan. (The testdata guarantees a>ba>b.)

How much money does Beryl need to prepare at least, to be sure that she can determine the number in Iris’s mind?

Input Format

The first line contains two positive integers aa and bb, and the number of test cases tt.
The next tt lines each contain a given positive integer nn, with the meaning as described above.

Output Format

Output tt lines. For each test case, output the minimum amount of money Beryl needs to prepare.

2 1 2
3
6
3
5
5 3 1
3
8

Hint

[Explanation for the 1st test case of Sample 1]

Beryl first asks about the set {1}\{1\}. If the answer is “Yes”, then Iris’s number is confirmed to be 11, and Beryl needs 22 yuan. If the answer is “No”, then Beryl asks about the set {2}\{2\}. Clearly, in the worst case she needs to spend another 22 yuan, for a total of 33 yuan, so the answer is 33 yuan.


[Constraints]

Test Point ID nn tt aa,bb
1 20\leq 20 10\leq 10 20\leq 20
2
3 2000\leq 2000 100\leq 100 500\leq 500
4
5
6
7
8 1018\leq 10^{18} 200\leq 200 a=2a=2,b=1b=1
9
10

Translated by ChatGPT 5