ALWFACT - Allowed Factors

Chico told his students that from now on, they would be referenced by numerical codes of up to 12 digits in official communications (emails and tasks). Then, he gave each student a card with a unique number written on it. The students quickly assumed this number was their code — but to their surprise (and Levi’s despair), Professor Chico explained that this was not their actual code.

A student’s code is the term at the position (indexed from 1) in a special ordered sequence S, where that position is the number written on their card. The sequence S has a unique property: each number in it, when decomposed into prime factors, can only include primes from a set of N numbers written on the board by the teacher. To make Levi’s life even harder, the set of primes changes every week, so he always has to recalculate his code to avoid missing deadlines.

Your task is to help Levi. Given the set of prime numbers written on the board during the week and the number on Levi’s card, determine what his weekly cod

Input

The input consists of multiple test cases.

Each test case begins with a line containing two integers N (1 ≤ N ≤ 102) and M (1 ≤ M ≤ 105) representing respectively the number of prime numbers written on the board by Professor Chico and the number on the student's card.

The second line contains N distinct prime numbers P₁, P₂, ..., Pₙ (2 ≤ Pi < 106), which form the allowed prime factor set for the week.

Input ends when a line with N = 0 and M = 0 is encountered.

Output

The output consists of a single line for each test case, containing Levi's weekly code.

Example

Input:
2 1
2 3
2 10
2 3
3 10
2 3 5
3 10
3 7 13
0 0

Output:
2
24
15
81

Added by:fepaf
Date:2018-05-21
Time limit:0.100s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: SQLITE

hide comments
2021-02-02 20:18:16 David
First Java AC!
2019-09-26 08:00:24
Clearer statement:
"A non-decreasing sequence is formed from product of any power and any number of a given set of primes. You have to find the Mth term."

Last edit: 2019-09-26 08:01:37
2019-07-03 21:07:43
sorting the prime numbers in desc order gives AC and in ascending order gives TLE. Any reason why?
2018-06-03 11:46:46
Good problem and interesting results.
2018-05-28 15:03:20
could you tell ..No of test case ?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.