Smallest Sub-Array
Submissions: 1022   Accuracy:

26.51%

  Difficulty: Medium   Marks: 4

Given an integer G and an array A[ ], find the length of the minimum sub-array whose Greatest Common Divisor equals to G.
 

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer G, where G is the required  Greatest Common Divisor. The second line of each test case contains an integer N, where N is the size of the array A[ ]. The third line of each test case contains N space separated integers denoting elements of the array A[ ].

 

Output:
Print out the length of the smallest sub-array with GCD = G. If there is no such sub-array formed, then print "-1". 

Constraints:
1 <= T <= 100
1 <   N <= 200
0<= A[i]<=100
1 <  G <= 100

Examples :

Input:

3
3
8
6 9 12 10 15 24 36 27
4
7
21 3 12 4 32 7 5
2
6
9 12 15 24 36 27

Output
2
2
-1 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Rohan Malhotra


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.