Kth element

1

1 votes
Problem

You are given an array of N integers (where A[i] denotes ith element of the array) . Each A[i] forms an arithmetic progression in which the first term is same as the common difference and is equal to A[i]. Now all the N arithmetic progressions are combined together to form a new set S. 

Your task is to find the Kth element of set S. 

Input Format

First line contains T (no. of testcases). 

First line of every testcase contains two integers N (no. of integers in array) and K . 

Second line of testcase contains N integers of Array.

Constraints

1<=T<=5 

1<=N<=10 

1<=A[i]<=50 

1<=K<=10^13 

Note: Every A[i] is prime number and all are pairwise distinct . 

Note: All elements in a set are distinct and in sorted order.

Output Format

Output the kth element in the set for each test case in a separate line.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

As N=2, so there are 2 arithmetic progressions. first term and common difference of first A.P is 2 and first term and common difference of second A.P is 3. thus set S contains { 2,3,4,6,8,9,10,12,14,15,16,18,20...... }. So, 10th element in this set is 15.

Editor Image

?