A16188 | Divide and Equalize
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $a$ consisting of $n$ positive integers. You can perform the following operation on it:
1. Choose a pair of elements $a_i$ and $a_j$ ( $1 \le i, j \le n$ and $i \neq j$ );
2. Choose one of the divisors of the integer $a_i$ , i.e., an integer $x$ such that $a_i \bmod x = 0$ ;
3. Replace $a_i$ with $\frac{a_i}{x}$ and $a_j$ with $a_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 $a$ = \[ $100, 2, 50, 10, 1$ \] with $5$ elements. Perform two operations on it:
1. Choose $a_3 = 50$ and $a_2 = 2$ , $x = 5$ . Replace $a_3$ with $\frac{a_3}{x} = \frac{50}{5} = 10$ , and $a_2$ with $a_2 \cdot x = 2 \cdot 5 = 10$ . The resulting array is $a$ = \[ $100, 10, 10, 10, 1$ \];
2. Choose $a_1 = 100$ and $a_5 = 1$ , $x = 10$ . Replace $a_1$ with $\frac{a_1}{x} = \frac{100}{10} = 10$ , and $a_5$ with $a_5 \cdot x = 1 \cdot 10 = 10$ . The resulting array is $a$ = \[ $10, 10, 10, 10, 10$ \].
After performing these operations, all elements in the array $a$ become equal to $10$ .
1. Choose a pair of elements $a_i$ and $a_j$ ( $1 \le i, j \le n$ and $i \neq j$ );
2. Choose one of the divisors of the integer $a_i$ , i.e., an integer $x$ such that $a_i \bmod x = 0$ ;
3. Replace $a_i$ with $\frac{a_i}{x}$ and $a_j$ with $a_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 $a$ = \[ $100, 2, 50, 10, 1$ \] with $5$ elements. Perform two operations on it:
1. Choose $a_3 = 50$ and $a_2 = 2$ , $x = 5$ . Replace $a_3$ with $\frac{a_3}{x} = \frac{50}{5} = 10$ , and $a_2$ with $a_2 \cdot x = 2 \cdot 5 = 10$ . The resulting array is $a$ = \[ $100, 10, 10, 10, 1$ \];
2. Choose $a_1 = 100$ and $a_5 = 1$ , $x = 10$ . Replace $a_1$ with $\frac{a_1}{x} = \frac{100}{10} = 10$ , and $a_5$ with $a_5 \cdot x = 1 \cdot 10 = 10$ . The resulting array is $a$ = \[ $10, 10, 10, 10, 10$ \].
After performing these operations, all elements in the array $a$ become equal to $10$ .
输入格式
The first line of the input contains a single integer $t$ ( $1 \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 $n$ ( $1 \le n \le 10^4$ ) — the number of elements in the array $a$ .
The second line of each test case contains exactly $n$ integers $a_i$ ( $1 \le a_i \le 10^6$ ) — the elements of the array $a$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^4$ .
Then follows the description of each test case.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 10^4$ ) — the number of elements in the array $a$ .
The second line of each test case contains exactly $n$ integers $a_i$ ( $1 \le a_i \le 10^6$ ) — the elements of the array $a$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^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" 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).
输入输出样例
输入 #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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted