#K56687. Subarray Sum Divisibility

    ID: 30254 Type: Default 1000ms 256MiB

Subarray Sum Divisibility

Subarray Sum Divisibility

You are given an integer K and an array of N integers. Your task is to determine whether there exists a contiguous subarray (of length at least one) whose sum is divisible by K.

In other words, for an array a1, a2, ..., aN, check if there exist indices 1 ≤ i ≤ j ≤ N such that:

\( \sum_{k=i}^{j} a_k \equiv 0 \pmod{K} \)

If such a subarray exists, print YES; otherwise, print NO for that test case.

Note: The solution should read input data from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The first line of input contains an integer T, the number of test cases.

For each test case, the first line contains two integers N and K, where N is the number of elements in the array and K is the divisor.

The next line contains N space-separated integers, representing the elements of the array.

outputFormat

For each test case, output a single line containing YES if there exists a contiguous subarray whose sum is divisible by K, and NO otherwise.

## sample
2
3 5
4 1 3
4 9
7 8 -5 12
YES

NO

</p>