#P16962. [SCCPC 2026] 交换余生

    ID: 19046 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>数学四川数论Special Judge枚举2026省赛/邀请赛

[SCCPC 2026] 交换余生

Problem Description

Given a sequence aa of length nn, determine whether there exists a sequence bb such that:

  • S(a)=S(b)S(a)=S(b), where S(a)S(a) and S(b)S(b) denote the multisets formed by all elements in sequences aa and bb, respectively.
  • There does not exist any 1i<n1 \le i < n such that gcd(b1,,bi)=gcd(bi+1,,bn)\gcd(b_1,\cdots,b_i) = \gcd(b_{i+1},\cdots,b_n).

Input Format

This problem contains multiple test cases.

The first line of the input contains a positive integer tt (1t101 \le t \le 10), indicating the number of test cases.

For each test case:

The first line contains a positive integer nn (2n2×1052 \le n \le 2 \times 10^5), indicating the length of sequence aa.

The second line contains nn positive integers a1,a2,,ana_1,a_2,\cdots,a_n (1ai10121 \le a_i \le 10^{12}), representing the sequence aa.

It is guaranteed that n2×105\sum n \le 2 \times 10^5.

Output Format

For each test case:

If there exists a sequence bb satisfying the conditions, output one line "YES"; otherwise, output one line "NO".

You may output the answer in any letter case. For example, "yEs", "yes", "Yes", and "YES" will all be accepted as correct.

7
4
6 12 24 15
5
2 4 3 9 6
6
2 3 5 4 9 25
4
7 7 14 21
2
10 20
3
6 6 6
5
14 21 22 33 17
YES
YES
NO
NO
YES
NO
YES

Hint

Translated by ChatGPT 5