#bzoj4488. 最大公约数

最大公约数

Title Description

Given a positive integer sequence Ai of length N, for any consecutive subsequence
{Al,Al+1...Ar}, We define its weight W (L, R) as the product of its length and the greatest common divisor of all elements in the sequence, that is W(L,R) = (R-L+1) ∗ gcd (Al..Ar)。
JYY hopes to find the subsequence with the highest weight.

Input format

Enter a line containing a positive integer N.
The next line contains N positive integers, representing the sequence Ai
1 < = Ai < = 10^12, 1 < = N < = 100,000

Output format

The output file contains a line of positive integers representing the weight of the subsequence with the highest weight.

5
30 60 20 20 20
80

The best subsequence is the subsequence composed of the last 4 elements.