Codeforces Round 628 (Div. 2)
E
Ehab's REAL Number Theory Problem
Codeforces
2600
原题
← DF →
翻译中…

You are given an array $a$ of length $n$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.

翻译中…

A sequence $a$ is a subsequence of an array $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements.

翻译中…

Input

翻译中…

The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of $a$.

翻译中…

The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 10^6$) — the elements of the array $a$.

翻译中…

Output

翻译中…

Output the length of the shortest non-empty subsequence of $a$ product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1".

翻译中…

Note

翻译中…

In the first sample, you can choose a subsequence $[1]$.

翻译中…

In the second sample, you can choose a subsequence $[6, 6]$.

翻译中…

In the third sample, you can choose a subsequence $[6, 15, 10]$.

翻译中…

In the fourth sample, there is no such subsequence.

翻译中…

样例

Input #1
3
1 4 6
Output #1
1
InputCopy OutputCopy
Input #2
4
2 3 6 6
Output #2
2
InputCopy OutputCopy
Input #3
3
6 15 10
Output #3
3
InputCopy OutputCopy
Input #4
4
2 3 5 7
Output #4
-1
InputCopy OutputCopy
题目信息
题号
1325E
时间限制
3 s
内存限制
256 MB
标签
暴力
DFS 及类似
图论
数论
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。