```
public class Solution {
public int nthSuperUglyNumber(int n, int[] primes) {
int len = primes.length;
int [] res = new int [n];
int [] idx = new int [len];
res[0] = 1;
for(int i =1;i<n;i++){
int min = Integer.MAX_VALUE;
for(int j=0;j<len;j++){
int temp2 = primes[j]*res[idx[j]];
if(temp2 == res[i-1]){
idx[j]++; // kill duplicate
temp2 = primes[j]*res[idx[j]];
}
if(temp2 < min)
min =temp2;
}
res[i] = min;
}
return res[n-1];
}
```

}