1053: [HAOI2007]反素数ant

来源:互联网 发布:python老男孩10期网盘 编辑:程序博客网 时间:2024/06/05 20:07

题目链接

xg(x)xg(x)>g(i)  0<i<xx,n

题解:x是反质数->x的因子多->x的质因子多,由一个数的因子个数计算式,取小质因子更优,然后大力搜,可以玄学剪枝一下

我的收获:质因子神啊,复杂度强啊

#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define INF 0x7fffffff#define ll long long int n,ans=1,num=1;int p[]={1,2,3,5,7,11,13,17,19,23,29,31};void dfs(int x,ll now,int cnt,int last){    if(x==12) return;    if(cnt>num||(cnt==num&&now<ans)) ans=now,num=cnt;//选因数多的……     for(int t=1,i=0;i<=last&&now*t<=n;i++,t*=p[x])        dfs(x+1,now*t,cnt*(i+1),i);}void init(){    scanf("%d",&n);    dfs(1,1,1,20);    printf("%d\n",ans);}int main(){    init();    return 0;}
原创粉丝点击