#K70917. Subsequence Prime Sum

    ID: 33415 Type: Default 1000ms 256MiB

Subsequence Prime Sum

Subsequence Prime Sum

Given an array of integers, determine if there exists any non-empty subsequence whose sum is a prime number and is greater than or equal to a given threshold \(P\). For each test case, you are provided with two integers \(N\) and \(P\), where \(N\) denotes the number of elements in the array, and \(P\) is the minimum value that a prime sum must achieve. You need to output "YES" if such a subsequence exists and "NO" otherwise.

A subsequence is a sequence that can be derived from the original array by deleting some or no elements without changing the order of the remaining elements. Note that the subsequence must be non-empty.

Example:

Input:
2
5 10
2 3 5 7 11
3 20
10 15 20

Output: YES NO

</p>

Here, in the first test case, the subsequence [3, 7] (sum = 10, which is not prime) is not valid, but the subsequence [2, 3, 7] has sum 12 which is not prime either. However, one valid subsequence is [5, 7] with sum 12 which still may not be prime. In fact, the answer is determined by verifying all possible non-empty subsequences and checking if any sum is a prime number and \(\ge P\). The provided sample input gives the output above.

inputFormat

The input is read from stdin and consists of multiple test cases. The first line contains a single integer \(T\) representing the number of test cases. Then, for each test case:

  • The first line contains two integers \(N\) and \(P\) separated by a space, where \(N\) is the number of elements in the array and \(P\) is the threshold.
  • The second line contains \(N\) space-separated integers representing the elements of the array.

It is guaranteed that the array size is small enough to allow checking all subsequences.

outputFormat

For each test case, output a single line to stdout: "YES" if there exists a non-empty subsequence whose sum is a prime number and is no less than \(P\), otherwise "NO".

## sample
2
5 10
2 3 5 7 11
3 20
10 15 20
YES

NO

</p>