#C11783. Absolute Difference Between Sum of Prime and Non-Prime Numbers

    ID: 41137 Type: Default 1000ms 256MiB

Absolute Difference Between Sum of Prime and Non-Prime Numbers

Absolute Difference Between Sum of Prime and Non-Prime Numbers

You are given an array of integers. Your task is to compute the absolute difference between the sum of prime numbers and the sum of non‐prime numbers in the array. If the array does not contain at least one prime and one non-prime, output -1.

Let \( S_{prime} \) be the sum of prime numbers and \( S_{nonprime} \) be the sum of non-prime numbers. You need to calculate \( |S_{prime} - S_{nonprime}| \). If either \( S_{prime} \) or \( S_{nonprime} \) is zero, then output \(-1\).

The program should read the input from standard input (stdin) and print the result for each test case to standard output (stdout).

inputFormat

The first line contains an integer \( T \) representing the number of test cases. Each test case is described in two lines. The first line of each test case contains an integer \( N \), denoting the number of elements in the array. The second line contains \( N \) space separated integers.

outputFormat

For each test case, output a single integer — the absolute difference between the sum of prime numbers and the sum of non-prime numbers, or \(-1\) if one of the sums is zero.

## sample
3
5
1 2 3 4 5
4
6 8 10 12
3
7 11 13
5

-1 -1

</p>