#P2723. n-th Ugly Number
n-th Ugly Number
n-th Ugly Number
Given a set of prime numbers \(S = \{p_1, p_2, \dots, p_k\}\), a positive integer is called an ugly number (with respect to \(S\)) if and only if every prime factor of the integer belongs to the set \(S\). Note that we do not consider \(1\) as an ugly number.
The ugly number set consists of numbers like \(p_1\), \(p_1 \times p_2\), \(p_1 \times p_1\), \(p_1 \times p_2 \times p_3\), etc. When these numbers are sorted in increasing order (with duplicates removed), your task is to find the \(n\text{-th}\) ugly number. It is guaranteed that the answer can be represented using a 32-bit signed integer.
inputFormat
The first line contains two integers \(k\) and \(n\) where \(k\) is the number of primes in the set \(S\) and \(n\) is the index of the ugly number to be found.
The second line contains \(k\) distinct prime numbers separated by spaces.
outputFormat
Output a single integer, the \(n\text{-th}\) ugly number from the ugly number set generated by \(S\).
sample
3 10
2 3 5
15