J. Prime Guess II
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Examples
Input
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
Output
55 6
60 6
-68 10
-58 6
41 6
20 6
79 6
Input
6 8
3 7 7 10 8 9
21 1
20 4
21 3
21 5
21 1
21 2
21 2
21 5
Output
170 3
-100 4
70 3
-27 6
170 3
140 3
140 3
-27 6
Note

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:

  • $$$score(1,4,6)=13+9+11=33$$$;
  • $$$score(2,4,6)=0+14+14=28$$$;
  • $$$score(3,4,6)=0+14-9=5$$$;
  • $$$score(4,4,6)=0+14+0=14$$$;
  • $$$score(5,4,6)=0-25+0=-25$$$;
  • for any other $$$i$$$, we have $$$score(i,4,6)=0+0+0=0$$$.
Therefore, the sum of scores for $$$r_1=6$$$ is $$$33+28+5+14-25=55$$$.

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$$$.