class Solution(object):
    def nthSuperUglyNumber(self, n,primes):
        """
        :type n: int
        :rtype: int
        """
        if n==0:
            return
        if n==1:
            return 1
        m=len(primes)
        k=[0 for i in range(n)]
        t=[0 for i in range(m)]
        k[0]=1
        for i in range(1,n,1):
            k[i]=min(primes[j]*k[t[j]] for j in range(m))
            for l in range(m):
                if k[i]==primes[l]*k[t[l]]:
                    t[l]+=1
        return k[n-1]
s=Solution()
n=12
primes=[2,7,13,19]
print(s.nthSuperUglyNumber(n,primes))
#每个ugly number都由原来的ugly number *2，*3，*5得到