1053. [HAOI2007]反素数ant【DFS+结论】

Description

  对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。如果某个正整数x满足:g(x)>g(i) 0<i<x
,则称x为反质数。例如,整数1,2,4,6等都是反质数。现在给定一个数N,你能求出不超过N的最大的反质数么

Input

  一个数N(1<=N<=2,000,000,000)。

Output

  不超过N的最大的反质数。

Sample Input

1000

Sample Output

840
 
www.cnblogs.com/CXCXCXC/p/4687940.html
要用到一些奇怪怪怪的性质的搜索题…
 
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #define LL long long
 5 using namespace std;
 6 LL  prime[15]={0,2,3,5,7,11,13,17,19,23,29,31,37};
 7 LL ans,num,n;
 8 void Dfs(LL now,LL mul,LL cnt,LL lastcnt,LL res)
 9 {
10     if (ans==res*(cnt+1) && mul<num)
11         num=mul;
12     if (res*(cnt+1)>ans)
13         ans=res*(cnt+1),num=mul;
14     if (mul*prime[now]<=n && cnt<lastcnt)
15         Dfs(now,mul*prime[now],cnt+1,lastcnt,res);
16     for (LL i=now+1;i<=10;++i)
17         if (mul*prime[i]<=n)
18             Dfs(i,mul,0,cnt,res*(cnt+1));
19 }
20 
21 int main()
22 {
23     scanf("%lld",&n);
24     Dfs(1,1,0,0x7fffffff,1);
25     printf("%lld\n",num);
26 }
posted @ 2018-03-31 20:55  Refun  阅读(131)  评论(0编辑  收藏  举报