您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: