bzoj1053: [HAOI2007]反素数ant

太凉了

搜索的练习做不下去了明天再做

先做点数学题压压惊

1~n区间内最约数个数最大中最小的那个数90反素数啊。

然后你可以发现它的指数是由低位到高位递减的。否则交换一下就被淘汰了。

爆搜

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int pr[10]={2,3,5,7,11,13,17,19,23,29};

int li,ymax,mmin;
LL quick_pow(LL d,int p)
{
    LL ret=1;
    while(p>0)
    {
        if(p%2==1)ret*=d;
        d*=d;p/=2;
    }
    return ret;
}
void dfs(int k,int last,LL tot,LL num)
{
    if(num>li)return ;
    if(k==-1)
    {
        if(ymax<tot||(ymax==tot&&mmin>num))
            ymax=tot, mmin=num;
        return ;
    }
    int dsf=li/num,p=0;
    while(dsf!=0)dsf/=pr[k],p++;
    LL mul=quick_pow(pr[k],p);
    for(int i=p;i>=last;i--,mul/=pr[k])
        dfs(k-1,i,tot*(1+i),num*mul);
}
int main()
{
    scanf("%d",&li);
    ymax=0;dfs(9,0,1,1);
    printf("%d\n",mmin);
    return 0;
}

 

 

posted @ 2018-07-10 15:02  AKCqhzdy  阅读(188)  评论(0编辑  收藏  举报