BZOJ 1053 [HAOI2007]反素数ant

∵某数约数个数=∏(每个质因子个数+1);

∴多选小的质因子肯定比大的划算

∴小的的指数一定大于等于大的;

又∵2*3*5*7*11*13*17*19*23*29*31*37=7420738134810;

∴暴力搜索;

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
typedef long long LL;
using namespace std;
LL prime[20]={0,2,3,5,7,11,13,17,19,23,29,31,37},n,now,nowans;
int nowcs;
void dfs(int cnt,LL now,int cs,int lim) {
    LL tmp=now;
    if(now>n) return;
    if(cnt==13) {
        if(!nowans||cs>nowcs||(cs>=nowcs&&now<nowans)) {nowans=now; nowcs=cs; }
        return ;
    }
    for(int i=0;i<=lim;i++) {
        if(tmp>n) break;
        dfs(cnt+1,tmp,cs*(i+1),i);
        tmp*=prime[cnt];
    }
}
int main()
{
    scanf("%lld",&n);
    dfs(1,1LL,1,31);
    printf("%lld",nowans);
    return 0;
}
View Code

 

posted @ 2017-09-17 17:00  啊宸  阅读(127)  评论(0编辑  收藏  举报