# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

You are given **n** positive integers as an array. Also, you are given an integer **k**. Now, try to find a subsequence of the array that **(LCM - GCD)** of that subsequence equals to **k**. You don’t have to print the subsequence, just print whether it is possible to find a subsequence with given condition or not!**Note:** Here, **LCM** means Least common multiple and **GCD** means Greatest common divisor. Also subsequence means a new array which can be generated by deleting some values of initial array without changing the order. **GCD** & **LCM** of single number are same and equal to the number of itself.

You have to answer **T** independent queries.

First line contains two integers **n** & **k**, the length of the array and the value of **(LCM - GCD)**. Second line contains **n** positive integers as an array **a**. Let, the value at **i ^{th}** position is

1 ≤ T ≤ 10

1 ≤ n ≤ 9

0 ≤ k ≤ 10

1 ≤ a

Subtask #2 (30 points)

1 ≤ T ≤ 10

1 ≤ n ≤ 10

0 ≤ k ≤ 10

1 ≤ a

Subtask #3 (60 points)

1 ≤ T ≤ 10

1 ≤ n ≤ 10

0 ≤ k ≤ 10

1 ≤ a

Print **“YES”**, if it is possible to find a subsequence which **(LCM - GCD)** equals to **k**. Otherwise, print **“NO”**.*Print them without quotes with a newline. And, try to use faster IO as the dataset is huge.*

Input | Output |
---|---|

5 5 3 2 4 8 3 6 3 22 6 8 12 3 20 6 8 12 3 6 6 8 12 3 10 6 8 12 | YES YES YES YES NO |

In first case, |

41% Solution Ratio

AST_TheCoderEarliest,

Ashraful_jnuFastest, 0.1s

serotoninLightest, 131 kB

serotoninShortest, 792B

Login to submit

For the first subtask, just find out all of the subsequences. In this case, the number of subsequenc...