#K82782. Multiple Subarray Sum

    ID: 36052 Type: Default 1000ms 256MiB

Multiple Subarray Sum

Multiple Subarray Sum

You are given an array of integers \(A\) and an integer \(X\). Your task is to determine if there is a non-empty contiguous subarray of \(A\) such that the sum of its elements is a multiple of \(X\). In other words, you need to check if there exists a pair of indices \(i, j\) (with \(i \leq j\)) for which:

\(\sum_{k=i}^{j} A[k] \equiv 0 \mod X\)

If such a subarray exists, output YES; otherwise, output NO.

Example:

  • For \(A = [1, 3, 2, 6, 4]\) and \(X = 10\), the subarray \([3, 2, 6]\) sums to 11 which is not a multiple of 10, but the subarray \([1,3,2,6,4]\) itself has a sum of 16 which is also not a multiple of 10; however, careful checking shows that there is a valid contiguous block that meets the criteria. (The example provided in the sample cases confirms that the answer is YES.)

Note that a subarray must be contiguous and non-empty.

inputFormat

The input is given via standard input (stdin) and is structured as follows:

  • The first line contains an integer \(T\), representing the number of test cases.
  • For each test case:
    • The first line contains two integers \(N\) and \(X\), where \(N\) is the number of elements in the array and \(X\) is the integer used to check divisibility.
    • The second line contains \(N\) space-separated integers, representing the array \(A\).

outputFormat

For each test case, output a single line to standard output (stdout) containing either YES or NO indicating whether a contiguous subarray exists whose sum is a multiple of \(X\).

## sample
1
5 10
1 3 2 6 4
YES

</p>