[Solution] K-Subarrays CodeChef Solution
Problem
You are given an array of positive integers. Let be the gcd of all the numbers in the array .
You have to find if there exist non-empty, non-intersecting subarrays of for which the arithmetic mean of the gcd of those subarrays equals .
Formally, let be the gcd of those chosen subarrays, then, should follow.
If there exist such subarrays, output YES
, otherwise output NO
.
Note: Two subarrays are non-intersecting if there exists no index , such that, is present in both the subarrays.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers — the number of integers in the array and the integer , respectively.
- The next line contains space-separated positive integers , the elements of the array .
Output Format
For each test case, if there exist such subarrays, output YES
, otherwise output NO
.
You may print each character of the string in uppercase or lowercase (for example, the strings YES
, yEs
, yes
,
and yeS
will all be treated as identical).
Explanation:
Test case : It is impossible to find non-empty, non-intersecting subarrays which satisfy the given condition.
Test case : There is only one element in the array. Here, and, for the subarray , . Thus, it is possible to satisfy the conditions.
Test case : Here, . We can choose non-empty, non-intersecting subarrays where , , and . Thus, the arithmetic mean = . Hence, we can have such subarrays.
Test case : It is impossible to find non-empty, non-intersecting subarrays which satisfy the given condition.
No comments:
Post a Comment