[ CQOI2016 ] 伪光滑数
作者:互联网
题目
思路
代码
#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;
}
标签:LOJ,include,61,光滑,43,long,int,CQOI2016 来源: https://www.cnblogs.com/Proteinlzl/p/14983188.html