#P5502. [JSOI2015] 最大公约数

    ID: 4395 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>暴力数据结构2015各省省选江苏分治

[JSOI2015] 最大公约数

Description

Given a sequence of positive integers AiA_i of length NN.

For any consecutive subsequence Al,Al+1,...,ArA_l, A_{l+1}, ..., A_r, define its weight W(L,R)W(L, R) as the product of its length and the greatest common divisor of all elements in the subsequence, i.e., W(L,R)=(RL+1)×gcd(Al,...,Ar)W(L, R) = (R - L + 1) × \gcd(A_l, ..., A_r).

JYY wants to find the subsequence with the maximum weight.

Input Format

The input contains one line with a positive integer NN.

The next line contains NN positive integers, representing the sequence AiA_i.

Output Format

Output one line with a positive integer, representing the maximum weight among all subsequences.

5
30 60 20 20 20
80

Hint

1Ai1012,1N1000001 \le A_i \le 10^{12}, 1 \le N \le 100000

Translated by ChatGPT 5