package leetcode;

/**
 * https://leetcode.com/problems/super-ugly-number/
 */
public class Problem313 {
    public int nthSuperUglyNumber(int n, int[] primes) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem313 prob = new Problem313();
    }
}

@@ -12,16 +12,43 @@
 tcode;%0A%0A
+import java.util.TreeSet;%0A%0A
 /**%0A * h
@@ -194,129 +194,1323 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem313 prob = new Problem313();
+TreeSet%3CLong%3E set = new TreeSet%3C%3E();%0A        for (int prime : primes) %7B%0A            set.add((long) prime);%0A        %7D%0A        set.add(1L);%0A        int i = 0;%0A        long result = 0;%0A        int primeIdx = -1;%0A        while (i %3C n) %7B%0A            result = set.pollFirst();%0A//            System.out.println(%22i = %22 + i);%0A//            System.out.println(%22  - popping %22 + result);%0A//            System.out.println(%22  - primeIdx: %22 + primeIdx);%0A            for (int j = 0; j %3C= primeIdx; j++) %7B%0A//                System.out.println(%22  - adding %22 + (result * primes%5Bj%5D));%0A                set.add(result * primes%5Bj%5D);%0A//                System.out.println(%22  - set: %22 + set);%0A            %7D%0A            i++;%0A            if (primeIdx %3C primes.length - 1) %7B%0A                primeIdx++;%0A            %7D%0A        %7D%0A        return (int) result;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem313 prob = new Problem313();%0A        System.out.println(prob.nthSuperUglyNumber(12, new int%5B%5D%7B2, 7, 13, 19%7D)); // 32%0A        System.out.println(prob.nthSuperUglyNumber(15, new int%5B%5D%7B3, 5, 7, 11, 19, 23, 29, 41, 43, 47%7D)); // 35%0A        System.out.println(prob.nthSuperUglyNumber(100000, new int%5B%5D%7B7,19,29,37,41,47,53,59,61,79,83,89,101,103,109,127,131,137,139,157,167,179,181,199,211,229,233,239,241,251%7D)); // 1092889481
 %0A   

Update problem 313