Easiest to understand solution
Somehow I find the available solutions are not that straight forward to understand.\nThis one is using heap. What it does is:\n1. Maintain a heap for all genera
Somehow I find the available solutions are not that straight forward to understand.\nThis one is using heap. What it does is:\n1. Maintain a heap for all generated ugly numbers.\n2. Once at a time, pop the minimal number from the heap. (for n times)\n3. For each new generated number, we push it into the heap if it has never show up. We use a set to make sure that the number in the heap is not duplicated.\n\nThis one is slow by the way. But it is easier to understand.\nO(N log(N*k))\n```\nclass Solution(object):\n    def nthSuperUglyNumber(self, n, primes):\n        if n==1: return 1\n        hp = [1] +  [i for i in primes]\n        used = set(hp)\n        heapq.heapify(hp)\n        num = 1\n        while n:\n            n-=1\n            num = heapq.heappop(hp)\n            for p in primes:\n                if num*p not in used:\n                    heapq.heappush(hp, num*p)\n                    used.add(num*p)\n        return num\n```
[]