Codeforces Round 948 (Div. 2)
C
Nikita and LCM
Codeforces
1900
原题
← BD →
翻译中…

Nikita is a student passionate about number theory and algorithms. He faces an interesting problem related to an array of numbers.

翻译中…

Suppose Nikita has an array of integers $a$ of length $n$. He will call a subsequence$^\dagger$ of the array special if its least common multiple (LCM) is not contained in $a$. The LCM of an empty subsequence is equal to $0$.

翻译中…

Nikita wonders: what is the length of the longest special subsequence of $a$? Help him answer this question!

翻译中…

$^\dagger$ A sequence $b$ is a subsequence of $a$ if $b$ can be obtained from $a$ by the deletion of several (possibly, zero or all) elements, without changing the order of the remaining elements. For example, $[5,2,3]$ is a subsequence of $[1,5,7,8,2,4,3]$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 2000$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 2000$) — the length of the array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array $a$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2000$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the length of the longest special subsequence of $a$.

翻译中…

Note

翻译中…

In the first test case, the LCM of any non-empty subsequence is contained in $a$, so the answer is $0$.

翻译中…

In the second test case, we can take the subsequence $[3, 2, 10, 1]$, its LCM is equal to $30$, which is not contained in $a$.

翻译中…

In the third test case, we can take the subsequence $[2, 3, 6, 100\,003]$, its LCM is equal to $600\,018$, which is not contained in $a$.

翻译中…

样例

Input #1
6
5
1 2 4 8 16
6
3 2 10 20 60 1
7
2 3 4 6 12 100003 1200036
9
2 42 7 3 6 7 7 1 6
8
4 99 57 179 10203 2 11 40812
1
1
Output #1
0
4
4
5
8
0
InputCopy OutputCopy
题目信息
题号
1977C
时间限制
2 s
内存限制
256 MB
标签
暴力
数据结构
动态规划
贪心
数学
数论
排序

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