bzoj1053: [HAOI2007]反素数ant

把数分解成质数乘积的形式,它的约数个数就可以表示成每个质因数的指数+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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值