public int nthSuperUglyNumber(int n, int[] primes) {
        if (n <= 0 || primes == null || primes.length == 0) return -1;
        int[] ugly = new int[n];
        int[] index = new int[primes.length];
        ugly[0] = 1;
        for (int i = 1; i < n; ++i) {
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < primes.length; ++k) {
                int num = primes[k] * ugly[index[k]];
                if (num < min) min = num;
            }
            ugly[i] = min;
            for (int k = 0; k < primes.length; ++k) {
                if (min == primes[k] * ugly[index[k]]) ++index[k];
            }
        }
        return ugly[n - 1];
    }