Python, generators on a heap
Solution 1 ... ~550 ms (updated July 2016, originally was ~1570 ms)\n\nUsing generators and heapq.merge. Too bad there's no itertools.unique.\n\n    def nthSupe
**Solution 1** ... ~550 ms (updated July 2016, originally was ~1570 ms)\n\nUsing generators and `heapq.merge`. Too bad there's no `itertools.unique`.\n\n    def nthSuperUglyNumber(self, n, primes):\n        uglies = [1]\n        def gen(prime):\n            for ugly in uglies:\n                yield ugly * prime\n        merged = heapq.merge(*map(gen, primes))\n        while len(uglies) < n:\n            ugly = next(merged)\n            if ugly != uglies[-1]:\n                uglies.append(ugly)\n        return uglies[-1]\n\n---\n\n**Solution 2** ... ~500 ms (updated July 2016, originally was ~1400 ms)\n\nSame thing done differently and it's a bit faster.\n\n    def nthSuperUglyNumber(self, n, primes):\n        uglies = [1]\n        merged = heapq.merge(*map(lambda p: (u*p for u in uglies), primes))\n        uniqed = (u for u, _ in itertools.groupby(merged))\n        map(uglies.append, itertools.islice(uniqed, n-1))\n        return uglies[-1]
['Python']