bzoj1053: [HAOI2007]反素数ant

1053: [HAOI2007]反素数ant

题目:传送门 

题解:

   首先要知道一个知识点:

   一个数的因数个数=所有不同质因数的次数+1后相乘

   假设:x=p1^x1*p2^x2*p3^x3

   那么x的因子个数就是(x1+1)*(x2+1)*(x3+1)

   那么依据题目,我们肯定是需要更多的因数,那就打个dfs吧

代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<cmath>
 5 #include<algorithm>
 6 #define qread(x) x=read()
 7 using namespace std;
 8 typedef long long LL;
 9 inline LL read()
10 {
11     LL f=1,x=0;char ch;
12     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
13     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
14     return f*x;
15 }
16 LL n;
17 LL p[15]={0,2,3,5,7,11,13,17,19,23,29,31,37};
18 LL s[1100];int ans,y;
19 void dfs(int x,int sum,LL multi)
20 {
21     if(x>12)return ;
22     if(sum>y || sum==y && multi<ans)
23     {
24         ans=multi;
25         y=sum;
26     }
27     s[x]=0;
28     while(multi*p[x]<=n && s[x]<s[x-1])
29     {
30         s[x]++;
31         multi*=p[x];
32         LL next=sum*(s[x]+1);
33         dfs(x+1,next,multi);
34     }
35 }
36 int main()
37 {
38     qread(n);ans=y=0;
39     s[0]=100000;
40     dfs(1,1,1);
41     printf("%lld\n",ans);
42     return 0;
43 }

 

posted @ 2018-01-04 13:47  CHerish_OI  阅读(177)  评论(0编辑  收藏  举报