#C7965. Sacred Sequence

    ID: 51894 Type: Default 1000ms 256MiB

Sacred Sequence

Sacred Sequence

You are given several test cases. For each test case, you are provided with a sequence of integers and a prime number \( P \). Your task is to determine whether there exists a non-empty contiguous subarray whose sum is divisible by \( P \); that is, if there exists a subarray whose sum \( S \) satisfies \( S \mod P = 0 \).

For example, given the sequence [1, 2, 3, 4, 5] and \( P = 3 \), one such subarray is [1, 2] because \( 1+2 = 3 \) and \( 3 \mod 3 = 0 \).

This problem requires a solution that checks all possible contiguous subarrays efficiently when the input size is small enough. Use your preferred programming language to implement a solution that reads from standard input and writes the answer to standard output.

inputFormat

The input begins with an integer \( T \) representing the number of test cases. Each test case consists of two lines:

  • The first line contains two integers \( N \) and \( P \), where \( N \) represents the number of integers in the sequence and \( P \) is a prime number.
  • The second line contains \( N \) space-separated integers.

outputFormat

For each test case, output a single line containing YES if there exists a non-empty contiguous subarray whose sum is divisible by \( P \); otherwise, output NO.

## sample
2
5 3
1 2 3 4 5
4 5
7 11 -8 14
YES

YES

</p>