#P15741. [JAG 2024 Summer Camp #2] Max Sum of GCD
[JAG 2024 Summer Camp #2] Max Sum of GCD
Description
For a sequence of positive integers where , let be the answer to the following problem:
- Among the positive integers , paint at least one and at most of them red, and paint the rest blue. Let be the greatest common divisor (GCD) of the integers painted red, and be the GCD of the integers painted blue. Find the maximum possible value of .
You are given a sequence of positive integers . You will also be given queries. For each query, you will be given two integers and such that . For each query, let $\boldsymbol{X} = (A_{l_i}, A_{l_i + 1}, \ldots, A_{r_i})$, and find .
Input Format
The input is given in the following format:
$$\begin{aligned} &N \\ &A_1 \ A_2 \ \ldots \ A_N \\ &Q \\ &l_1 \ r_1 \\ &l_2 \ r_2 \\ &\vdots \\ &l_Q \ r_Q \end{aligned}$$- for all
- for all
Output Format
Print lines. On the -th line (), output the answer to the -th query.
6
3 6 2 5 4 4
3
1 3
4 6
1 6
7
9
7
京公网安备 11011102002149号