题目描述
Teja is extremely enthusiastic about competitive programming , but sometimes fails miserably even for easy problems. Utkarsh , his best friend gave him one array A of N elements , to perform the given operation.
Given two integers P and Q , Teja needs to find Q elements of the given array which are closest to P ,with each having atleast 1 prime factor in common with P.
Note that these Q elements should be in non-decreasing order. Also, if obtaining such condition is not possible , print “-1” without quotes.
Question update : Incase of multiple answers, select the minimum number. Eg. if P=15 and you need to decide between 12 and 18, select 12.
Input :
T - the number of test cases.
For each test case , you have 3 lines of input.
First line has N- number of elements.
Second line has array A .
Third line has 2 integers P and Q.
Output:-
For each test case , print the elements satisfying above condition in non-decreasing order separated by a space.
If such a case is not possible , simply print “-1” without double quotes.
Constraints :
1 ≤ T ≤ 10
1 ≤ N ≤ 10^5
1 ≤ A[i] ≤ 10^5
2 ≤ P ≤ 10^5
1 ≤ Q ≤ 100
Note:- If there are multiple answers possible , print the smallest ones .
For eg.
N=2
array elements- 12 18
p=15
q=1
Possible answers are - 12 as well as 18
but smallest is 12.
So print 12
Time limit : 1 sec
Problem Setter :
Utkarsh Srivastava
Problem Tester:
Shivam Garg
SAMPLE INPUT
1
5
1 4 5 7 10
8 2
SAMPLE OUTPUT
4 10
Explanation
There is only 1 test case , comprising 5 elements -1,4,5,7,10 .
P is 8 and Q is 2.
Now for the given array we have 2 (i.e Q) closest elements with P are 4 and 10 , provided that they have 2 as common prime factor.
输入格式
见题面
输出格式
见题面