Description
A super ugly number has all prime factors in the given primes array. Return the nth super ugly number.
Examples
Input:
n = 12, primes = [2,7,13,19]Output:
32Explanation:
First 12 super ugly numbers with primes [2,7,13,19].
Input:
n = 12, primes = [1]Output:
1Explanation:
Edge case with a single-element array.
Input:
n = 8, primes = [3,5,7]Output:
21Explanation:
The first 8 super ugly numbers with primes [3,5,7] are: 1, 3, 5, 7, 9, 15, 21, 25. Each number's prime factors are only from the given set {3,5,7}. For example: 9=3×3, 15=3×5, 21=3×7, 25=5×5.
Constraints
- •
1 ≤ n ≤ 10⁵ - •
1 ≤ primes.length ≤ 100