#P10700. [SNCPC2024] 猜质数 II
[SNCPC2024] 猜质数 II
Problem Description
To secretly prepare a mysterious prime number, MCPlayer542 racked his brains.
Then he invented a clever stupid method and named it “Prime Score”.
He prepared distinct numbers as test points, and defined the “Prime Score” as follows:
where
$$f(x,y)=\left\{\begin{array}{rcl}u-y, & x=1 \\ u, & 1<x\le y,\ \gcd(x,y)=1 \\ -x\cdot y, & x\neq 1,\ \gcd(x,y)=x \\ 0, & \text{otherwise} \end{array}\right.$$As you can see, the “Prime Score” of a prime number is usually relatively high but still useless.
So MCPlayer542 panicked. Now he only wants to brute force test randomly and obtain a total score . He plans to test times. Each test gives and , where is the parameter in the function .
For each query, he wants to know the maximum total score he can get, and the smallest that can achieve this maximum total score.
Input Format
The first line of the input contains two integers (), separated by a single space.
The second line contains integers (), separated by single spaces, representing the testdata of the test points.
The next lines each contain two integers (), separated by a single space, representing one query.
Output Format
For each query, output one line with two numbers: the maximum total score for the query and the smallest () that can achieve this score, separated by a single space.
10 7
10 9 2 1 5 3 10 10 1 8
14 4
17 5
13 10
16 1
12 4
16 6
16 3
55 6
60 6
-68 10
-58 6
41 6
20 6
79 6
6 8
3 7 7 10 8 9
21 1
20 4
21 3
21 5
21 1
21 2
21 2
21 5
170 3
-100 4
70 3
-27 6
170 3
140 3
140 3
-27 6
Hint
In the first query of Sample 1, . If we choose , then the final total score is . Here:
- ;
- ;
- ;
- ;
- ;
- for other values of , we have .
Therefore, when the total score is .
It can be proven that no larger total score can be obtained for other values of . Therefore the answer is , and the smallest that achieves it is .
Translated by ChatGPT 5