C++/priority_queue approach/O(nlogk)
\nclass Solution {\npublic:\n    struct Pair{\n        long long val;\n        long long ptr;\n        long long product;\n        Pair(){}\n        Pair(long l
```\nclass Solution {\npublic:\n    struct Pair{\n        long long val;\n        long long ptr;\n        long long product;\n        Pair(){}\n        Pair(long long _val,long long _ptr,long long _product){\n            val=_val;\n            ptr=_ptr;\n            product=_product;\n        }\n    };\n    struct compare{\n        bool operator()(const Pair&a,const Pair &b){\n            return a.product>b.product;\n        }\n    };\n    int nthSuperUglyNumber(int n, vector<int>& primes) {\n        priority_queue<Pair,vector<Pair>,compare>pq;\n        vector<long long> dp(n+1);\n        dp[1]=1;\n        for(int i=0;i<primes.size();i++){\n            pq.push(Pair(primes[i],1,primes[i]));\n        }\n        \n        int i=2;\n        while(i<=n){\n            Pair src=pq.top();pq.pop();\n            if(src.product!=dp[i-1]){\n                dp[i++]=src.product;\n            }\n            pq.push(Pair(src.val,src.ptr+1,dp[src.ptr+1]*src.val));\n            \n        }\n       \n        \n        return dp[n];\n        \n    }\n};\n```
['C', 'Heap (Priority Queue)']