[ CQOI2016 ] 伪光滑数

题目

Luogu
LOJ
Acwing

思路

001.png
002.png

代码

#include <iostream>
#include <queue>
#define int long long
using namespace std;
int n, k, P[] = { 2, 3, 5, 7, 11, 13, 17, 19,
                  23, 29, 31, 37, 41, 43, 47, 53,
                  59, 61, 67, 71, 73, 79, 83, 89, 
                  97, 101, 103, 107, 109, 113, 127 };
struct NODE { int val, p, k, lim; };
bool operator<(NODE a, NODE b) { return a.val < b.val; }
priority_queue<NODE> H;
signed main() {
    cin >> n >> k;
    for (int i = 0, j; j = P[i], i <= 30; i++) 
        for (int k = 1; j <= n; k++, j = j * P[i])
            H.push((NODE){ j, P[i], k, i - 1 });
    while (k--) {
        NODE t = H.top(); H.pop();
        if (!k) return cout << t.val << endl, 0;
        else if (t.k <= 1) continue;
        else for (int i = 0; i <= t.lim; i++)
            H.push((NODE){ t.val / t.p * P[i], t.p, t.k - 1, i });
    }
    return 0;
}
posted @ 2021-07-07 19:21  Protein_lzl  阅读(49)  评论(0编辑  收藏  举报