bzoj1053: [HAOI2007]反素数ant

来源:互联网 发布:购买域名骗局 编辑:程序博客网 时间:2024/04/24 05:40

把数分解成质数乘积的形式,它的约数个数就可以表示成每个质因数的指数+1的和

明显一个可能是答案的数较小的质因数的指数应比较大质因数的指数小

然后暴力枚举出这样的数就行了

#include <cstdio>#include <cstring>#include <queue>using namespace std;#define MAXP 10long 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