#C5567. Splitting into Alternating Prime Sequences
Splitting into Alternating Prime Sequences
Splitting into Alternating Prime Sequences
You are given several test cases. In each test case, you will receive a sequence of integers. Your task is to determine whether by filtering out the prime numbers from the sequence, it is possible to form two alternating subsequences (one consisting of even primes and the other of odd primes). Note that a valid alternating sequence must contain at least one even prime and one odd prime. In other words, if the list of primes contains fewer than 2 elements or if all the primes are of the same parity, then the answer is "NO"; otherwise, the answer is "YES".
Note: The only even prime is 2. All other prime numbers are odd.
Formal Explanation:
Let \( P \) be the set of prime numbers in the sequence. If \(|P| < 2\) then output "NO". Otherwise, if there exists at least one even prime (i.e. 2) and at least one odd prime in \( P \), output "YES"; otherwise, output "NO".
inputFormat
The first line contains an integer \( T \), the number of test cases. Each test case is described as follows:
- The first line of each test case contains an integer \( N \), the number of elements in the sequence.
- The second line contains \( N \) space-separated integers representing the sequence.
Input is read from stdin
.
outputFormat
For each test case, output a single line with either "YES" or "NO" depending on whether the sequence's prime numbers can be split into two alternating sequences (one even, one odd).
Output is written to stdout
.
2
6
3 2 5 11 7 13
4
4 6 8 10
YES
NO
</p>