#K94557. Equalizing Array Elements

    ID: 38667 Type: Default 1000ms 256MiB

Equalizing Array Elements

Equalizing Array Elements

Sophie has an array of n integers. She can perform the following operation any number of times (up to a maximum of k operations): choose any two integers in the array and replace them with their product. Formally, in one operation you select two indices and update both values to the product of the two numbers. Sophie wonders if it is possible to make all integers in the array equal by performing no more than k operations.

Note that if the array is already composed of equal integers, the answer is YES. Otherwise, even if operations are allowed (k > 0), under the constraints of this problem it has been determined that making all elements equal is not possible. Also, if no operations are allowed (k = 0) and the array is not uniform, then the answer is NO.

The mathematical formulation is as follows:

\[ \text{Given an array } A = [a_1, a_2, \dots, a_n] \text{ and an integer } k, \text{ output } \textbf{YES} \text{ if } a_1 = a_2 = \cdots = a_n, \text{ otherwise output } \textbf{NO}. \]

inputFormat

The input is read from standard input (stdin) and follows the format below:

T
n k
a1 a2 ... an
... (repeated for T test cases)

Where:

  • T is the number of test cases.
  • For each test case, the first line contains two integers: n (the number of elements in the array) and k (the maximum number of operations allowed).
  • The second line contains n integers representing the elements of the array.

outputFormat

For each test case, print a single line to standard output (stdout) containing either YES if it is possible to make all array elements equal, or NO otherwise.

## sample
1
4 7
1 1 1 1
YES

</p>