#P15066. [UOI 2024 II Stage] GCD, Sum, Multiply. What?...
[UOI 2024 II Stage] GCD, Sum, Multiply. What?...
题目描述
The author has used up all the creative skills on previous problems, so Anton won't be tortured in this statement. He will just give you an interesting problem.
You are given an array consisting of integers. You are also given queries . For each query, find the maximum value of $\operatorname{sum}[tl;tr] \times \operatorname{gcd}[tl;tr]$ over all pairs (), where
- ;
- --- the sum of all numbers in the segment ;
- --- the greatest common divisor of all numbers in the segment .
The greatest common divisor of two numbers and is the largest positive integer that divides both and .
The greatest common divisor of a set of numbers is the largest positive integer that divides all elements of the set.
输入格式
The first line contains two integers , () --- the number of elements in the array and the number of queries, respectively.
The second line contains integers () --- the description of the array.
Each of the next lines contains two integers , () --- the description of the queries.
输出格式
Print integers --- the answers to the queries.
3 2
3 3 2
1 3
2 3
18
9
8 6
2 4 8 8 8 2 4 16
1 8
2 5
3 4
2 4
7 7
3 6
256
192
128
128
16
192
提示
In the first example, there are following segments:
- --- $\operatorname{sum}[1;1] \times \operatorname{gcd}[1;1]$ = = ;
- --- $\operatorname{sum}[1;2] \times \operatorname{gcd}[1;2]$ = = ;
- --- $\operatorname{sum}[1;3] \times \operatorname{gcd}[1;3]$ = = ;
- --- $\operatorname{sum}[2;2] \times \operatorname{gcd}[2;2]$ = = ;
- --- $\operatorname{sum}[2;3] \times \operatorname{gcd}[2;3]$ = = ;
- --- $\operatorname{sum}[3;3] \times \operatorname{gcd}[3;3]$ = = .
Scoring
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): no additional constraints.