public int nthSuperUglyNumber1(int n, int[] primes) {

        PriorityQueue<Node> pq = new PriorityQueue<>();
        for (int i = 0; i < primes.length; i++) {
            pq.offer(new Node(i, 0, primes[i]));
        }
        int[] val = new int[n];
        val[0] = 1;
        for (int i = 1; i < n; ) {
            Node node = pq.poll();
            if (val[i-1] != node.val) {
                val[i] = node.val;
                i++;
            }
            node.index = node.index + 1;
            node.val = primes[node.inputIndex]*val[node.index];
            pq.offer(node);
        }
        return val[n - 1];
    }
Date 03/08/2016
@author Tushar Roy

Find nth ugly number.

https://leetcode.com/problems/ugly-number-ii/
https://leetcode.com/problems/super-ugly-number/
http://www.geeksforgeeks.org/ugly-numbers/
src/com/interview/dynamic/UglyNumbers.java