CF1881D.Divide and Equalize

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa consisting of nn positive integers. You can perform the following operation on it:

  1. Choose a pair of elements aia_i and aja_j (1≤i,j≤n1 \le i, j \le n and i≠ji \neq j);
  2. Choose one of the divisors of the integer aia_i, i.e., an integer xx such that ai mod x=0a_i \bmod x = 0;
  3. Replace aia_i with aix\frac{a_i}{x} and aja_j with aj⋅xa_j \cdot x.

Determine whether it is possible to make all elements in the array the same by applying the operation a certain number of times (possibly zero).

For example, let's consider the array aa = [100,2,50,10,1100, 2, 50, 10, 1] with 55 elements. Perform two operations on it:

  1. Choose a3=50a_3 = 50 and a2=2a_2 = 2, x=5x = 5. Replace a3a_3 with a3x=505=10\frac{a_3}{x} = \frac{50}{5} = 10, and a2a_2 with a2⋅x=2⋅5=10a_2 \cdot x = 2 \cdot 5 = 10. The resulting array is aa = [100,10,10,10,1100, 10, 10, 10, 1];
  2. Choose a1=100a_1 = 100 and a5=1a_5 = 1, x=10x = 10. Replace a1a_1 with a1x=10010=10\frac{a_1}{x} = \frac{100}{10} = 10, and a5a_5 with a5⋅x=1⋅10=10a_5 \cdot x = 1 \cdot 10 = 10. The resulting array is aa = [10,10,10,10,1010, 10, 10, 10, 10].

After performing these operations, all elements in the array aa become equal to 1010.

给你一个由 nn 个正整数组成的数组 aa。你可以对它执行以下操作:

  1. 选择一对元素 aia_i 和 aja_j(其中 1≤i,j≤n1 \le i, j \le n 且 i≠ji \neq j);
  2. 选择整数 aia_i 的一个约数,即选择一个整数 xx,使得 ai mod x=0a_i \bmod x = 0;
  3. 将 aia_i 替换为 aix\frac{a_i}{x},并将 aja_j 替换为 aj⋅xa_j \cdot x。

判断是否可以通过若干次(可能为零次)执行该操作,使得数组中所有元素都相等。

例如,考虑包含 55 个元素的数组 a=[100,2,50,10,1]a = [100, 2, 50, 10, 1]。对其执行两次操作:

  1. 选择 a3=50a_3 = 50 和 a2=2a_2 = 2,取 x=5x = 5。将 a3a_3 替换为 a3x=505=10\frac{a_3}{x} = \frac{50}{5} = 10,将 a2a_2 替换为 a2⋅x=2⋅5=10a_2 \cdot x = 2 \cdot 5 = 10。得到的新数组为 a=[100,10,10,10,1]a = [100, 10, 10, 10, 1];
  2. 选择 a1=100a_1 = 100 和 a5=1a_5 = 1,取 x=10x = 10。将 a1a_1 替换为 a1x=10010=10\frac{a_1}{x} = \frac{100}{10} = 10,将 a5a_5 替换为 a5⋅x=1⋅10=10a_5 \cdot x = 1 \cdot 10 = 10。得到的新数组为 a=[10,10,10,10,10]a = [10, 10, 10, 10, 10]。

执行完这些操作后,数组 aa 中的所有元素均变为 1010。

输入格式

The first line of the input contains a single integer tt (1≤t≤20001 \le t \le 2000) — the number of test cases.

Then follows the description of each test case.

The first line of each test case contains a single integer nn (1≤n≤1041 \le n \le 10^4) — the number of elements in the array aa.

The second line of each test case contains exactly nn integers aia_i (1≤ai≤1061 \le a_i \le 10^6) — the elements of the array aa.

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

输入的第一行包含一个整数 tt(1≤t≤20001 \le t \le 2000),表示测试用例的数量。

随后是每个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1041 \le n \le 10^4),表示数组 aa 中的元素个数。

每个测试用例的第二行包含恰好 nn 个整数 aia_i(1≤ai≤1061 \le a_i \le 10^6),表示数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 10410^4。

输出格式

For each test case, output a single line:

  • "YES" if it is possible to make all elements in the array equal by applying the operation a certain (possibly zero) number of times;
  • "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as a positive answer).

对于每个测试用例,输出一行:

  • 如果可以通过应用该操作若干次(可能为零次)使得数组中所有元素相等,则输出 "YES";
  • 否则输出 "NO"。

你可以以任意大小写形式输出答案(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

    7
    5
    100 2 50 10 1
    3
    1 1 1
    4
    8 2 4 2
    4
    30 50 27 20
    2
    75 40
    2
    4 4
    3
    2 3 1

    输出#1

    YES
    YES
    NO
    YES
    NO
    YES
    NO

说明/提示

The first test case is explained in the problem statement.

第一个测试用例在题目描述中已作解释。

输入解题思路,AI测评打分。不知道怎么写?

首页