CF2084B.MIN = GCD

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

MIN = GCD

You are given a positive integer sequence aa of length nn. Determine if it is possible to rearrange aa such that there exists an integer ii (1i<n1 \le i \lt n) satisfying $$ \min([a_1,a_2,\ldots,a_i])=\gcd([a_{i+1},a_{i+2},\ldots,a_n]).$$

Heregcd(c)\gcd(c)denotes the greatest common divisor ofcc, which is the maximum positive integer that divides all integers incc.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (2n1052 \le n \le 10^5).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai10181 \le a_i \le 10^{18}).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, output "Yes" if it is possible, and "No" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, rearrange aa to [1,1][1,1] and let i=1i=1, then min([1])=gcd([1])\min([1])=\gcd([1]).

In the second test case, it can be shown that it is impossible.

In the third test case, rearrange aa to [3,2,2][3,2,2] and let i=2i=2, then min([3,2])=gcd([2])\min([3,2])=\gcd([2]).

In the fifth test case, rearrange aa to [3,4,5,6,9][3,4,5,6,9] and let i=3i=3, then min([3,4,5])=gcd([6,9])\min([3,4,5])=\gcd([6,9]).

Samples

7
2
1 1
2
1 2
3
2 2 3
3
2 3 4
5
4 5 6 9 3
3
998244359987710471 99824435698771045 1000000007
6
1 1 4 5 1 4
Yes
No
Yes
No
Yes
Yes
Yes

在线编程 IDE

建议全屏模式获得最佳体验