K Divisible Sequence

4.5

2 votes
basics of algorithms, String
Problem

Mr. Seth provides you a sequence of integers a1, a2, ..., an. Your task is to find whether you can make the sequence as K divisible sequence by adding d as many times as you require until a[i] <= 2*104

Note: A K divisible sequence is the sequence of integers where each integer is divisible by K.

Example - 

N=5, K=2, and d=1
Sequence: 1 2 3 4 5

So you can make this sequence K divisible sequence just by adding d 1 time in elements 1,3 and 5 of the given sequence.

Input

  • The first line of the input contains an integer T describing the number of test cases.
  • The first line of T test cases contains three space-separated integers N, K, and D.
  • The last line of the test case contains N space-separated integers.

Output

Print 'YES' if it is possible to make sequence K divisible else 'NO' in each test case.


Constraints

  • 1 <= T <= 10
  • 1 <= N,K,D <= 100
  • 1 <= A [i]<= 1000
Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

In the first test case, it is not possible to make sequence 3 divisible as only one element is divisible by 3.

In the second test case, you can make sequence 5 divisible by adding d=3 so that sequence becomes 5 10 15 20 5 15 25 25 35 40.
 

Editor Image

?