No.983 Convolution
Problem Statement
There is a sequence $A$ of positive integers consisting of $N$ terms, from the $0$-th term to the $N-1$-th term.
However, the values of some $0$ or more of the terms can be chosen freely.
Define a sequence $B$ of positive integers consisting of $N$ terms, from the $0$-th term to the $N-1$-th term, as follows.
- $\displaystyle B_k = \sum_{i\& j=k} (A_i \times A_j)$
The greatest common divisor of $B$ is defined as the largest positive integer that divides the values of all terms of $B$.
Find the maximum possible value of the greatest common divisor of $B$ when the values of the terms of $A$ are chosen optimally.
However, if the maximum value of the greatest common divisor does not exist, output $-1$.
Input
$N$
$A_0\ A_1\ \ldots A_{N-1}$
$1 \leq N \leq 2 \times 10^5$
$1 \leq A_i \leq 10^9$ or $A_i=-1$
The value of the $i$-th term can be chosen freely among positive integers if and only if $A_i=-1$
All inputs are integers
Output
Output the answer in one line.
Sample
Sample 1
Input
3 -1 -1 -1
Output
-1
For any arbitrarily large integer $M$, there is a way to choose the terms that makes the greatest common divisor larger than $M$.
Sample 2
Input
5 7 9 3 5 1
Output
1
Sample 3
Input
5 -1 54 -1 12 -1
Output
36
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tubuann1
beet