Aparoksha Number

0

0 votes
Problem

For a given set of K prime numbers S = {p1, p2, ..., pK}, consider the set of all numbers whose prime factors are a subset of S. This set contains, for example, p1, p1p2, p1p1, and p1p2p3 (among others). This is the set of `aparoksha numbers' for the input set S. Note: The number 1 is NOT a aparoksha number. Vishnu wants to find the nth aparoksha number. You need to help him. Your job is to find the Nth largest aparoksha number for a given set S. Long integers will be adequate for all solutions. 1 <= K <= 50, 1 <= N <= 1000, Primes are less than 1000

Input : First line contains number of test cases (maximum of 50 test caess). For each test case, the first line has two numbers K and N. The second line of the test case contains the K primes described.

Output: For each test case, print the nth aparoksha number.

Setter : SP Harish

Sample Input
3
1 3
2
4 19
2 3 5 7
1 1
3
Sample Output
8
27
3
Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?