#P2527. Panda's Mystical Sieve

    ID: 15797 Type: Default 1000ms 256MiB

Panda's Mystical Sieve

Panda's Mystical Sieve

Panda is a math fanatic who is fascinated not by the primes remaining after sieving, but by the numbers that get eliminated. He believes that among these eliminated numbers hide important cosmic secrets waiting to be discovered.

To uncover these mysteries, Panda focuses on numbers whose prime factors are all drawn from a given set. For example, if the allowed prime factors are \(2\) and \(3\), the numbers of interest are \(2, 3, 4, 6, 8, 9, \ldots\) (note that \(1\) is not included since it has no prime factors). Given a cosmic coefficient \(k\), your task is to find the \(k\)th smallest number among these numbers.

inputFormat

The input consists of two lines. The first line contains two integers \(m\) and \(k\), where \(m\) is the number of allowed prime factors and \(k\) is Panda's cosmic coefficient. The second line contains \(m\) distinct prime numbers separated by spaces.

outputFormat

Output the \(k\)th smallest number whose prime factors are all contained in the given set.

sample

2 5
2 3
8