#K15041. Subarray Sum Divisibility

    ID: 24268 Type: Default 1000ms 256MiB

Subarray Sum Divisibility

Subarray Sum Divisibility

You are given an array of integers and an integer K. Your task is to determine whether there exists a non-empty contiguous subarray whose sum is divisible by K. In other words, find if there exists a contiguous segment of the array such that if you sum up its elements, the result is a multiple of K.

Formally, given an array A[1...N] and an integer K, you need to determine if there exists indices i and j with 1 ≤ i ≤ j ≤ N such that

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

Note: If K is 0, then no valid subarray exists so the output should be "NO".

inputFormat

The input is given via standard input (stdin) and has the following format:

T
N1 K1
A1[1] A1[2] ... A1[N1]
N2 K2
A2[1] A2[2] ... A2[N2]
...
NT KT
AT[1] AT[2] ... AT[NT]

Here, T denotes the number of test cases, each test case consists of the number of elements N and an integer K on one line followed by N integers representing the array elements.

outputFormat

For each test case, output a single line to standard output (stdout) containing either "YES" if there exists a contiguous subarray whose sum is divisible by K, or "NO" otherwise.

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

YES

</p>