Leetcode 313 Solution
This article provides solution to leetcode question 313 (super-ugly-number)
Access this page by simply typing in "lcs 313" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/super-ugly-number
Solution
class Solution {
public:
int nthSuperUglyNumber(int n, vector<int>& primes) {
set<int64_t> a;
a.insert(1);
for (int i = 1; i < n; i++)
{
int64_t curr = *a.begin();
for (int j = 0; j < primes.size(); j++)
{
if (curr * primes[j] > INT_MAX)
break;
a.insert(curr * primes[j]);
}
a.erase(a.begin());
}
return *a.begin();
}
};