| 2024 ICPC ShaanXi Provincial Contest |
|---|
| Finished |
MCPlayer542 had a hard time trying to prepare a mysterious prime number.
He then invented a geniusstupid way to do it, and named it "prime score".
He prepared $$$n$$$ different numbers $$$a_1,\ a_2,\ \ldots,\ a_n$$$ as tests, and defined the "prime score" $$$score(x,l,r)$$$ as follows:
$$$$$$score(x,l,r)=\sum_{i=l}^r{f(x,a_i)}$$$$$$ where $$$$$$f(x,y)=\left\{\begin{array}{rcl}u-y, & x=1 \\ u, & 1 \lt x\le y,\ \gcd(x,y)=1 \\ -x\cdot y, & x\neq 1,\ \gcd(x,y)=x \\ 0, & \text{otherwise}. \end{array}\right.$$$$$$
It can be seen that the "prime score" of a prime number is usually higher but it still doesn't help.
So MCPlayer542 is angry, now his only plan is to run a brute-force on the test and get a sum of score $$$\sum_{i=1}^{10^6}{score(i,l,r)}$$$. He will test $$$q$$$ times, given $$$u$$$ and $$$l$$$ for each test, where $$$u$$$ is an argument to the function $$$f(x,y)$$$.
For each query, he wants to know the maximum sum of score that can be obtained and the minimum $$$r$$$ to get the maximum sum of score.
The first line contains two integers $$$n,\ q$$$ ($$$1\le n,\ q\le 5\times 10^5$$$) — the number of tests and the number of queries, separated by a single space.
The second line contains $$$n$$$ integers $$$a_1,\ a_2,\ \ldots,\ a_n$$$ ($$$1\le a_i\le 10^6$$$) — the value of each test, separated by single spaces.
Each of the following $$$q$$$ lines contains two integers $$$u_i,\ l_i$$$ ($$$1\le u_i \le 1.8\times 10^7,\ 1\le l_i\le n$$$), separated by a single space, denotes a query.
For every query, output two integers separated by a single space — the maximum sum of score and the minimum $$$r_i$$$ ($$$l_i\le r_i\le n$$$) to get the maximum sum of score.
10 710 9 2 1 5 3 10 10 1 814 417 513 1016 112 416 616 3
55 6 60 6 -68 10 -58 6 41 6 20 6 79 6
6 83 7 7 10 8 921 120 421 321 521 121 221 221 5
170 3 -100 4 70 3 -27 6 170 3 140 3 140 3 -27 6
In the first query of Sample 1, $$$u_1=14,\ l_1=4$$$. If we choose $$$r_1=6$$$, the final sum of score is $$$\sum_{i=1}^{10^6}{score(i,4,6)}$$$. We can see that:
It can be shown that a larger sum of scores cannot be obtained for any other value of $$$r_1$$$, so the answer is $$$55$$$ and the minimum $$$r_1$$$ to get the sum is $$$6$$$.
| Name |
|---|


