bzoj 1053 [ HAOI 2007 ] 反素数ant ——暴搜

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1053

试图打表找规律,但无果...

看TJ了,暴搜;

注意参数 w 是 long long。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,ans,mx,pri[12]={2,3,5,7,11,13,17,19,21,23};
void dfs(int ps,int cnt,int lst,ll w)//注意w是ll 
{
    if(cnt>mx)mx=cnt,ans=(int)w;
    else if(cnt==mx)ans=min(ans,(int)w);
    if(ps>8)return;//
    for(int i=0;i<=lst&&w<=n;i++,w*=pri[ps])
        dfs(ps+1,cnt*(i+1),i,w);
}
int main()
{
    scanf("%d",&n);
    dfs(0,1,32,1);
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2018-07-25 10:48  Zinn  阅读(171)  评论(0编辑  收藏  举报