text: #include<vector>
  #include<iostream>
  #include<queue>
  #include<functional>
  using namespace std;
  struct Elem{
      int val;//prime*ret[retidx]
      int prime;
      int retidx;
      Elem(int v,int p,int r):val(v),prime(p),retidx(r){};
  };
  bool operator<(const Elem& e1,const Elem& e2){
      return e1.val>e2.val;
  };
  void SuperUglyNumber(vector<int>& primes,vector<int>& ret, int n){
      priority_queue<Elem> pq;
      Elem tmp(1,1,0);
      ret.push_back(1);
      for(auto prime:primes) pq.push({1,prime,-1});
      while(ret.size()<n){
          tmp=pq.top();
          pq.pop();
          tmp.retidx++;
          tmp.val=tmp.prime*ret[tmp.retidx];
          pq.push(tmp);
          if(pq.top().val!=ret.back()) 
              ret.push_back(pq.top().val);
      } 
  }
  int main(){
      vector<int> primes{3,5,7};
      vector<int> ret;
      SuperUglyNumber(primes,ret,20);
      for(auto& val:ret) cout<<val<<" ";
      cout<<endl;
      return 0 ;
  }