mex和gcd的乘积
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

曾经的A,为何如今沦落成了C
                                                    ——来自一场连续出三个妙妙签到题的良心出题人
给你一个长度为n的数列。求这个数列中连续区间的\operatorname{mex}\operatorname{gcd}最大值是多少?

形式化的:定义f(l,r)=\operatorname{mex}(a_l,...,a_r)\times \operatorname{gcd}(a_l,...,a_r)\ ,\ l\le r。求f(l,r)_{max}
关于\operatorname{mex}:区间的\operatorname{mex}被定义为区间中未出现的最小的非负整数,例如:
  • [2,2,1]\operatorname{mex}0,因为0不在这个区间中
  • [3,1,0,1]\operatorname{mex}2,因为0,1在这个区间中,而2不在这个数组中
  • [0,3,1,2]\operatorname{mex}4,因为0,1,2,3在这个区间中,而4不在这个数组中
关于\operatorname{gcd}连续区间的最大公约数是指一个数列中相邻的若干个数字的最大公约数,同时也是最大能被区间中所有数整除的数。特殊的,对于任意非负整数x\operatorname{gcd}(0,x)=x\operatorname{gcd}(x)=x,例如:
  • \operatorname{gcd}(6,4,3)=\operatorname{gcd}(\operatorname{gcd}(6,4),3)=\operatorname{gcd}(2,3)=1
  • \operatorname{gcd}(5,2,0)=\operatorname{gcd}(\operatorname{gcd}(5,2),0)=\operatorname{gcd}(1,0)=1
  • \operatorname{gcd}(5)=5

输入描述:

第一行包含一个整数\ n\ (1\le n\le10^5),表示数列的长度
第二行包含n个非负整数\ a_1,a_2...,a_n\ (0\le a_i\le n),表示该数列

输出描述:

输出一个整数,表示数列中连续区间的\operatorname{mex}\operatorname{gcd}的最大值
示例1

输入

复制
5
0 1 2 1 4

输出

复制
3

说明

选择区间[1,4],此时f(1,4)=\operatorname{mex}(0,1,2,1)\times \operatorname{gcd}(0,1,2,1)=3\times 1=3,取得最大值。区间[1,5]同样也能取到最大值3
示例2

输入

复制
3
0 1 0

输出

复制
2

说明

选择区间[1,2],此时f(1,2)=\operatorname{mex}(0,1)\times \operatorname{gcd}(0,1)=2\times 1=2,取得最大值。区间[1,3][2,3]同样也能取到最大值2