#P7790. [COCI 2016/2017 #6] Gauss
[COCI 2016/2017 #6] Gauss
Description
You are given integers , and define for . You are also given lucky integers and their prices , and integers .
At the beginning, there is an integer on the blackboard. You can perform the following two operations:
-
Let the current number on the blackboard be . You may write down any divisor of that is smaller than , paying . Here denotes the number of divisors of the positive integer (including ).
-
If is a lucky integer, you may keep on the blackboard, paying .
Define as the minimum cost to start from , perform operations, and finally leave on the blackboard. Given and , compute .
Input Format
The first line contains a positive integer .
The second line contains positive integers .
The third line contains a positive integer .
The fourth line contains positive integers .
The fifth line contains a positive integer .
The next lines each contain two positive integers and , indicating that is a lucky number and its price is .
The -th line contains a positive integer , the number of queries.
The next lines each contain two positive integers and .
Output Format
For each query, output .
4
1 1 1 1
2
1 2
2
2 5
4 10
1
4 2
7
3
6 9 4
2
5 7
3
1 1
7 8
6 10
2
6 2
70 68
118
-2
3
8 3 10
2
8 4
3
1 6
5 1
3 7
2
5 1
3 1
16
66
Hint
Sample Explanation #1
Since , replace with , so the cost is .
Since , there are two ways to turn into :
-
Replace with , and since is a lucky number, keep in the second step. The cost is .
-
Since is a lucky number, keep in the first step, then replace with in the second step. The cost is .
The first plan is cheaper, so choose the first plan.
Therefore, the answer is .
Constraints
For of the testdata, , , , , , , , , .
Notes
The score of this problem follows the original COCI setting, with a full score of .
Translated from COCI2016_2017 CONTEST #6 T6 GAUSS.
Translated by ChatGPT 5
京公网安备 11011102002149号