':type n: int
:type primes: List[int]
:rtype: int'

def nthSuperUglyNumber(self, n, primes):

    ugly_number = 0
    heap = []
    heapq.heappush(heap, 1)
    for p in primes:
        heapq.heappush(heap, p)
    for _ in xrange(n):
        ugly_number = heapq.heappop(heap)
        for i in xrange(len(primes)):
            if ((ugly_number % primes[i]) == 0):
                for j in xrange((i + 1)):
                    heapq.heappush(heap, (ugly_number * primes[j]))
                break
    return ugly_number
