bzoj1053: [HAOI2007]反素数ant
2014-09-10 18:28
393 查看
把数分解成质数乘积的形式,它的约数个数就可以表示成每个质因数的指数+1的和
明显一个可能是答案的数较小的质因数的指数应比较大质因数的指数小
然后暴力枚举出这样的数就行了
明显一个可能是答案的数较小的质因数的指数应比较大质因数的指数小
然后暴力枚举出这样的数就行了
#include <cstdio> #include <cstring> #include <queue> using namespace std; #define MAXP 10 long long n; int p[MAXP] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; struct qtype { long long data; int ct[MAXP]; qtype(long long _data, int *_ct) : data(_data) { memcpy(ct, _ct, sizeof(ct)); } bool operator> (const qtype &x)const { return data > x.data; } }; int ct[MAXP] = {0}; priority_queue<qtype, vector<qtype>, greater<qtype> > q; int main() { scanf("%lld", &n); q.push(qtype(1, ct)); long long ans = 1, mct = 0, last = 0; while (!q.empty()) { long long a = q.top().data; memcpy(ct, q.top().ct, sizeof(ct)); q.pop(); if (a == last) continue; last = a; long long t = 1; for (int i = 0; i < MAXP; ++i) t *= ct[i] + 1; for (int i = 0; i < MAXP && a * p[i] <= n; ++i) { if (i && ct[i] + 1 > ct[i - 1]) continue; ++ct[i]; q.push(qtype(a * p[i], ct)); --ct[i]; } if (t > mct) mct = t, ans = a; } printf("%lld\n", ans); return 0; }
相关文章推荐
- 【BZOJ1053】[HAOI2007]反素数ant 暴力
- 【BZOJ】1053: [HAOI2007]反素数ant(贪心+dfs)
- [BZOJ 1053] [HAOI 2007] 反素数ant
- BZOJ 1053 [HAOI2007]反素数ant(约数个数)
- Bzoj1053 [HAOI2007]反素数ant
- BZOJ1053: [HAOI2007]反素数ant
- BZOJ1053(HAOI2007)反素数ant--暴搜
- bzoj 1053: [HAOI2007]反素数ant 搜索
- 【BZOJ 1053】 1053: [HAOI2007]反素数ant (反素数)
- BZOJ 1053 [HAOI2007]反素数ant
- [bzoj1053][HAOI2007]反素数ant【暴力】
- BZOJ——T 1053: [HAOI2007]反素数ant
- 【BZOJ1053】【DFS】【打表】[HAOI2007]反素数ant 题解
- BZOJ 1053 [HAOI2007]反素数ant
- 【BZOJ】1053: [HAOI2007]反素数ant
- bzoj 1053 [HAOI2007]反素数ant
- [BZOJ 1053][HAOI2007]反素数ant:搜索
- BZOJ 1053: [HAOI2007]反素数ant(DFS)
- BZOJ 1053: [HAOI2007]反素数ant 数论,DFS
- [dfs] BZOJ1053: [HAOI2007]反素数ant