310146: CF1789A. Serval and Mocha's Array

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Serval and Mocha's Array

题意翻译

对于一个正整数数组 $ a $ ,如果 $ a $ 中所有元素的最大公约数不超过其长度,那么这个数组就是**好**的。 对于一个至少有 $ 2 $ 个正整数的数组,如果其长度不小于 $ 2 $ 的所有前缀都是好的,那么这个数组就是**完美**的。 例如: - $ [3,6] $ 不好,因为$ \gcd(3,6)=3 $大于其长度 $ 2 $ 。 - $ [1,2,4] $ 既好又完美,因为其长度不小于 $ 2 $ 的所有前缀,即 $ [1,2] $ 和 $ [1,2,4] $ ,都是好的。 - $ [3,6,1] $ 好但不完美,因为$ [3,6] $ 不好。 给定一个含有 $ n $ 个正整数的数组,请你判断数组 $ a $ 是否可以**通过重新排列 $ a $ 中的元素**而**变得完美**。

题目描述

Mocha likes arrays, and Serval gave her an array consisting of positive integers as a gift. Mocha thinks that for an array of positive integers $ a $ , it is good iff the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of all the elements in $ a $ is no more than its length. And for an array of at least $ 2 $ positive integers, it is beautiful iff all of its prefixes whose length is no less than $ 2 $ are good. For example: - $ [3,6] $ is not good, because $ \gcd(3,6)=3 $ is greater than its length $ 2 $ . - $ [1,2,4] $ is both good and beautiful, because all of its prefixes whose length is no less than $ 2 $ , which are $ [1,2] $ and $ [1,2,4] $ , are both good. - $ [3,6,1] $ is good but not beautiful, because $ [3,6] $ is not good. Now Mocha gives you the gift array $ a $ of $ n $ positive integers, and she wants to know whether array $ a $ could become beautiful by reordering the elements in $ a $ . It is allowed to keep the array $ a $ unchanged.

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1\leq t\leq 500 $ ). The description of the test cases follows. The first line of each test case contains a single integer $ n $ ( $ 2\leq n\leq 100 $ ) — the length of array $ a $ . The second line of each test case contains $ n $ integers $ a_1,a_2,\ldots,a_n $ ( $ 1\leq a_1,a_2,\ldots,a_n\leq 10^6 $ ) — the elements of array $ a $ .

输出格式


For each test case, print Yes if it is possible to reorder the elements in $ a $ to make it beautiful, and print No if not. You can output Yes and No in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

输入输出样例

输入样例 #1

6
2
3 6
3
1 2 4
3
3 6 1
3
15 35 21
4
35 10 35 14
5
1261 227821 143 4171 1941

输出样例 #1

No
Yes
Yes
No
Yes
Yes

说明

In the first test case, neither $ [3,6] $ nor $ [6,3] $ are beautiful, so it's impossible to obtain a beautiful array by reordering the elements in $ a $ . In the second test case, $ [1,2,4] $ is already beautiful. Keeping the array $ a $ unchanged can obtain a beautiful array.

Input

题意翻译

对于一个正整数数组 $ a $ ,如果 $ a $ 中所有元素的最大公约数不超过其长度,那么这个数组就是**好**的。 对于一个至少有 $ 2 $ 个正整数的数组,如果其长度不小于 $ 2 $ 的所有前缀都是好的,那么这个数组就是**完美**的。 例如: - $ [3,6] $ 不好,因为$ \gcd(3,6)=3 $大于其长度 $ 2 $ 。 - $ [1,2,4] $ 既好又完美,因为其长度不小于 $ 2 $ 的所有前缀,即 $ [1,2] $ 和 $ [1,2,4] $ ,都是好的。 - $ [3,6,1] $ 好但不完美,因为$ [3,6] $ 不好。 给定一个含有 $ n $ 个正整数的数组,请你判断数组 $ a $ 是否可以**通过重新排列 $ a $ 中的元素**而**变得完美**。

Output

**题目大意:**

对于正整数数组 $ a $,如果数组中所有元素的最大公约数不超过数组长度,则称这个数组是**好**的。对于至少含有 $ 2 $ 个正整数的数组,如果其长度不小于 $ 2 $ 的所有前缀都是好的,那么这个数组就是**完美**的。给定一个含有 $ n $ 个正整数的数组 $ a $,请判断数组 $ a $ 是否可以通过重新排列其元素而变得完美。

**输入输出数据格式:**

- **输入格式:**
- 第一行包含一个整数 $ t $($ 1 \leq t \leq 500 $),表示测试用例的数量。
- 每个测试用例包含两行:
- 第一行包含一个整数 $ n $($ 2 \leq n \leq 100 $),表示数组 $ a $ 的长度。
- 第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $($ 1 \leq a_1, a_2, \ldots, a_n \leq 10^6 $),表示数组 $ a $ 的元素。

- **输出格式:**
- 对于每个测试用例,如果可以通过重新排列数组 $ a $ 的元素使其变得完美,则输出 "Yes",否则输出 "No"。
- "Yes" 和 "No" 的输出不区分大小写。**题目大意:** 对于正整数数组 $ a $,如果数组中所有元素的最大公约数不超过数组长度,则称这个数组是**好**的。对于至少含有 $ 2 $ 个正整数的数组,如果其长度不小于 $ 2 $ 的所有前缀都是好的,那么这个数组就是**完美**的。给定一个含有 $ n $ 个正整数的数组 $ a $,请判断数组 $ a $ 是否可以通过重新排列其元素而变得完美。 **输入输出数据格式:** - **输入格式:** - 第一行包含一个整数 $ t $($ 1 \leq t \leq 500 $),表示测试用例的数量。 - 每个测试用例包含两行: - 第一行包含一个整数 $ n $($ 2 \leq n \leq 100 $),表示数组 $ a $ 的长度。 - 第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $($ 1 \leq a_1, a_2, \ldots, a_n \leq 10^6 $),表示数组 $ a $ 的元素。 - **输出格式:** - 对于每个测试用例,如果可以通过重新排列数组 $ a $ 的元素使其变得完美,则输出 "Yes",否则输出 "No"。 - "Yes" 和 "No" 的输出不区分大小写。

加入题单

算法标签: