GCD Choice

3.3

9 votes
, Basic Math, Algorithms, Math
Problem

Y has no one to talk but he has an array \(a_1, a_2, ..., a_n\). Y wants to remove one element of array, so the gcd value of the remaining array (\(gcd(a_1, a_2, ..., a_{j-1}, a_{j+1}, ..., a_n)\)\(j\) is removed) is maximum.

What is the maximum value Y can get by removing exactly one element of the array?

Input

First line contains only \(n\), legnth of array.

Second line contains the array elements \(a_1, a_2, ..., a_n\)separated by space.

\(2 \leq n \leq 2 \times 10^5\)

\(1 \leq a_i \leq 10^9\)

Output

The only line of output contains an integer, maximum value value that Y can get.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

If Y removes the last element, gcd value of the remaining array will become \(gcd(6, 2, 6, 6, 2) = 2\).

Editor Image

?