#K7231. Count Special Integers
Count Special Integers
Count Special Integers
In this problem, you are given an integer array and you need to determine the number of special integers in it. An integer is considered special if it is equal to the sum of some contiguous subarray of the array. Note that a contiguous subarray can be as small as a single element.
For example, consider the array [1, 2, 3, 4]
:
- The subarray
[1, 2]
has a sum of3
, and since3
is present in the array, it is counted as special. - Every single element is also a contiguous subarray of length 1, so it is trivially a candidate.
Your task is to count the number of special integers for each test case.
Note: For any array A of size N, the total number of contiguous subarrays is \(\frac{N(N+1)}{2}\). Use efficient methods to avoid unnecessary computations if possible.
inputFormat
The input begins with a single integer T on the first line, representing the number of test cases.
Each test case consists of the following two lines:
- The first line contains an integer N, the number of elements in the array.
- The second line contains N space-separated integers that form the array.
outputFormat
For each test case, output a single line containing one integer — the number of special integers in the corresponding array.
## sample2
4
1 2 3 4
5
1 2 1 3 1
4
5
</p>