#K77172. Subarray Sum Divisibility

    ID: 34806 Type: Default 1000ms 256MiB

Subarray Sum Divisibility

Subarray Sum Divisibility

You are given an integer array and an integer k. Your task is to determine whether there exists a non-empty contiguous subarray whose sum is divisible by k. Formally, given an array a[0], a[1], ..., a[n-1], check if there exist indices i and j with i ≤ j such that:

\(\sum_{t=i}^{j}a_t \equiv 0 \pmod{k}\)

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

Note: The subarray must contain at least one element.

inputFormat

The input is read from stdin and is structured as follows:

  • The first line 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 array elements.

outputFormat

For each test case, output a single line to stdout containing either YES if there exists a subarray with a sum divisible by k, or NO otherwise.

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

YES

</p>