313. Super Ugly Number
Description
Difficulty: Medium
Related Topics: Array, Math, Dynamic Programming
A super ugly number is a positive integer whose prime factors are in the array primes
.
Given an integer n
and an array of integers primes
, return the nth super ugly number.
The nth super ugly number is guaranteed to fit in a 32-bit signed integer.
Example 1:
1 | Input: n = 12, primes = [2,7,13,19] |
Example 2:
1 | Input: n = 1, primes = [2,3,5] |
Constraints:
- 1 <= n <= 105
1 <= primes.length <= 100
2 <= primes[i] <= 1000
primes[i]
is guaranteed to be a prime number.- All the values of
primes
are unique and sorted in ascending order.
Hints/Notes
- priority queue
Solution
Language: C++
1 | class Solution { |