Question: Write java to solve: You are given an array of integers 1 , 2 , . . . , a 1 , a 2 ,

Write java to solve: You are given an array of integers 1,2,...,a1,a2,...,an of length n and an integer k.
Two players are playing a game. The first player chooses an index 11in. Then the second player chooses a different index 1,1jn,ij. The first player wins if |||aiaj| is not divisible by k. Otherwise, the second player wins.
We play as the first player. Determine whether it is possible to win, and if so, which index i should be chosen.
The absolute value of a number x is denoted by |||x| and is equal to x if 0x0, and x otherwise.
Input
Each test contains multiple test cases. The first line of input contains a single integer t (11001t100) the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and k (11001n100; 11001k100) the length of the array and the number k.
The second line of each test case contains integers 1,2,...,a1,a2,...,an (11001ai100) the elements of the array .
Output
For each test case, if it is impossible for the first player to win, print "NO"(without quotes).
Otherwise, print "YES" (without quotes) and on the next line the appropriate index 11in. If there are multiple solutions, print any of them.
Example
Input
7
32
123
42
1245
53
107345
53
131155536
21
1717
22
1718
13
6
Output
YES 2 NO YES 3 NO NO YES 2 YES 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!