Simple 5line Java Solution Using heap
`````````````````\nclass Solution {\n    public int nthSuperUglyNumber(int n, int[] p) {\n        PriorityQueue pq=new PriorityQueue<>();\n        pq.add(1l);\n
`````````````````\nclass Solution {\n    public int nthSuperUglyNumber(int n, int[] p) {\n        PriorityQueue<Long> pq=new PriorityQueue<>();\n        pq.add(1l);\n        for(int i=1;i<n;i++){\n            long l=pq.poll();\n            while(!pq.isEmpty() && pq.peek()==l){\n                pq.poll();\n            }\n           for(int j=0;j<p.length;j++){\n               pq.add(p[j]*l);\n           }\n        }\n        \n        return pq.poll().intValue();\n    }\n    \n}
['Heap (Priority Queue)', 'Java']