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

def nthSuperUglyNumber(self, n, primes):

    uglies = ([0] * n)
    uglies[0] = 1
    ugly_by_prime = list(primes)
    idx = ([0] * len(primes))
    for i in xrange(1, n):
        uglies[i] = min(ugly_by_prime)
        for k in xrange(len(primes)):
            if (uglies[i] == ugly_by_prime[k]):
                idx[k] += 1
                ugly_by_prime[k] = (primes[k] * uglies[idx[k]])
    return uglies[(-1)]
