Using min-heap, Accepted Java and Python code
The idea is similar to 264 Ugly Number II. The insight is that each new ugly number is generated from the previous ugly number by multiplying one of the prime. 
The idea is similar to 264 Ugly Number II. The insight is that each new ugly number is generated from the previous ugly number by multiplying one of the prime. Thus we can maintain a pointer for each prime which indicates the current position of the generated ugly number list. Then there is a new ugly number from each prime, then we find the minimum one from them. Naturally the minimum one can be found by min-heap.\n\nThe Java version is accepted by 474 ms, but not the python version. \n\n**UPDATE**: Thanks **Stefan** for pointing out that the complexity of this algorithm is **NOT** O(nlog(k)). I have modified the Python code and it was just accepted by 800 ms; the modified Java code is accepted by 160 ms. I will keep the original inefficient code here and Please check the updated code below...\n\nJava\n\n    import java.util.Comparator;\n    import java.util.PriorityQueue;\n    public class Solution {\n    public int nthSuperUglyNumber(int n, int[] primes) {\n\t\tComparator<Number> comparator = new NumberCompare();\n\t\tPriorityQueue<Number> queue = \n\t            new PriorityQueue<Number>(primes.length, comparator);\n\t\tfor(int i = 0; i < primes.length; i ++) \n\t\t\tqueue.add(new Number(primes[i], 0, primes[i]));\n\t\tint[] uglyNums = new int[n];\n\t\tuglyNums[0] = 1;\n\t\tfor(int i = 1; i < n; i++){\n\t\t\tNumber min = queue.peek();\n\t\t\tuglyNums[i] = min.un;\n\t\t\twhile(queue.peek().un == min.un){\n\t\t\t\tNumber tmp = queue.poll();\n\t\t\t\tqueue.add(new Number(uglyNums[tmp.pos + 1] * tmp.prime, tmp.pos+1, tmp.prime)); \n\t\t\t}\n\t\t}\n\t\t\n\t\treturn uglyNums[n-1];\n    }\n    \n\tpublic class Number{\n\t\tint un;\n\t\tint pos;\n\t\tint prime;\n\t\tNumber(int un, int pos, int prime){\n\t\t\tthis.un = un;\n\t\t\tthis.pos = pos;\n\t\t\tthis.prime = prime;\n\t\t}\n\t}\n\t\n\tpublic class NumberCompare implements Comparator<Number>{\n\n\t\t@Override\n\t\tpublic int compare(Number x, Number y) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\tif (x.un > y.un)\n\t\t\t\treturn 1;\n\t\t\telse if (x.un < y.un)\n\t\t\t\treturn -1;\n\t\t\telse\n\t\t\t\treturn 0;\n\t\t}\n\t}\n}\n\n\n\nPython \n\n    class Solution(object):\n    def nthSuperUglyNumber(self, n, primes):\n        """\n        :type n: int\n        :type primes: List[int]\n        :rtype: int\n        """\n        # Use the heap to find the next one\n        import heapq\n        q, uglyNums = [], [1]\n        k = len(primes)\n        for i in range(k): heapq.heappush(q, (primes[i], 0, primes[i]))\n        while len(uglyNums) < n:\n            x, i, p = q[0]\n            uglyNums += [x]\n            while q and q[0][0] == x:\n                x, i, p = heapq.heappop(q)\n                heapq.heappush(q, (p * uglyNums[i+1], i+1, p))\n        return uglyNums[-1]
['Python', 'Java']