[bzoj1053][HAOI2007]反素数ant【暴力】

【题目链接】
  http://www.lydsy.com/JudgeOnline/problem.php?id=1053
【题解】
  反素数有一个性质:质数的次幂递减。然后暴力就行了。

/* --------------
    user Vanisher
    problem bzoj-1053
----------------*/
# include <bits/stdc++.h>
# define    ll      long long
# define    inf     0x3f3f3f3f
# define    N       110
using namespace std;
ll read(){
    ll tmp=0, fh=1; char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') fh=-1; ch=getchar();}
    while (ch>='0'&&ch<='9'){tmp=tmp*10+ch-'0'; ch=getchar();}
    return tmp*fh;
}
ll p[N],mx,n,now,j,pnum,mxnum;
void dfs(ll k, ll les, ll x, ll num){
    if (num>mxnum||num==mxnum&&x<mx)
        mx=x, mxnum=num;
    ll i=p[k], j=1;
    while (x*i<=n&&j<=les){
        dfs(k+1,j,x*i,num*(j+1));
        j++; i=i*p[k];
    }
}
int main(){
    n=read(); now=1, j=1;
    while (now<=n){
        j++; bool f=true;
        for (ll i=2; i*i<=j; i++)
            if (j%i==0){
                f=false;
                break;
            }
        if (f){
            now=now*j;
            p[++pnum]=j;
        }
    }
    dfs(1,inf,1,1);
    printf("%lld\n",mx);
    return 0;
}
posted @ 2018-03-06 19:27  Vanisher  阅读(87)  评论(0编辑  收藏  举报