Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: vulkan
- * created: 29.07.2021 04:22:14 PM
- **/
- #include <bits/stdc++.h>
- typedef long long LL;
- using namespace std;
- int nthSuperUglyNumber(int n, vector<int> &primes) {
- priority_queue<LL, vector<LL>, greater<LL>> min_heap;
- map<LL, bool> vis;
- min_heap.push(1);
- while (n--) {
- LL x = min_heap.top();
- min_heap.pop();
- if (n == 0) {
- return x;
- }
- for (LL y : primes) {
- if (not vis[x * y]) {
- min_heap.push(x * y);
- vis[x * y] = true;
- }
- }
- }
- return 0;
- }
- int main(int argc, char const *argv[]) {
- int n;
- cin >> n;
- int m;
- cin >> m;
- vector<int> primes(m);
- for (int i = 0; i <= m - 1; ++i) {
- cin >> primes[i];
- }
- cout << nthSuperUglyNumber(n, primes);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement