public int nthUglyNumber2(int n) {
        Queue<Long> q2 = new LinkedList<Long>();
        Queue<Long> q3 = new LinkedList<Long>();
        Queue<Long> q5 = new LinkedList<Long>();
        q2.offer(1l);
        long num = -1;
        for (int i = 0; i < n; ++i) {
            long n2 = q2.peek();
            long n3 = q3.isEmpty() ? Integer.MAX_VALUE : q3.peek();
            long n5 = q5.isEmpty() ? Integer.MAX_VALUE : q5.peek();
            num = Math.min(n2, Math.min(n3, n5));
            if (num == n2) {
                q2.poll();
                q2.offer(2 * num);
                q3.offer(3 * num);
                q5.offer(5 * num);
            } else if (num == n3) {
                q3.poll();
                q3.offer(3 * num);
                q5.offer(5 * num);
            } else {
                q5.poll();
                q5.offer(5 * num);
            }
        }
        return (int) num;
    }