Smallest sequence with given Primes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| vector<int> Solution::solve(int A, int B, int C, int D) { unordered_set<int> vis; priority_queue<int, vector<int>, greater<int>> q; auto push = [&](int n) { if(!vis.count(n)) { vis.insert(n); q.push(n); } }; push(A); push(B); push(C); vector<int> res; while(res.size() < D) { auto u = q.top(); q.pop(); res.push_back(u); push(A * u); push(B * u); push(C * u); } return res; }
|