Doubled Distances CodeChef Solution | CodeChef Problem Solution 2022
You are given integers . Determine whether they can be reordered such that each pair of consecutive differences differ by a factor of .
Formally, determine whether there exists a rearrangement of the given integers into an array such that, for each , at least one of the following two conditions holds:
- , or
Note that different conditions can hold at different indices — the only restriction is that at each index, at least one of the given conditions must hold. Please see the sample tests below for examples.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases. The description of test cases follows.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer, .
- The second line of each test case contains space-separated integers, denoting .
Output Format
For each test case, output in a single line the answer — if a rearrangement that satisfies the given conditions exists, and otherwise.
The output is not case sensitive, so for example the strings , etc. will all be treated as correct.
Constraints
- The sum of across all test cases won't exceed
Sample Input 1
4
3
5 2 4
5
2 1 16 8 4
5
97 98 100 96 88
6
16 19 18 21 24 22
Sample Output 1
Yes
Yes
No
Yes
Explanation
Test case : Rearrange the numbers to form . The consecutive differences are , and .
Test case : One possible rearrangement is . The consecutive differences are consecutive powers of .
Test case : No rearrangement of the numbers satisfies the condition. For example, one rearrangement is with consecutive differences . and do not differ by a factor of (they differ by a factor of ), so this is not a valid arrangement.
Join Now for Solution:-
No comments:
Post a Comment