BZOJ——T 1053: [HAOI2007]反素数ant

http://www.lydsy.com/JudgeOnline/problem.php?id=1053

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

HINT

 

Source

设 x=p1*^k1*p2^k2+p3^k3;则g(x)=(k1+1)*(k2+1)*(k3+1);

又因为2*3*5*7*11*13*17*19*23*26>maxn,

所以可以搜索使用的素数,该素数的次数,以及当前的x

貌似是求使g(x)最大的最小的x,以为我求最大的xWA了、、

 1 #include <cstdio>
 2 
 3 #define LL long long
 4 LL n,ans=1,tmp;
 5 LL ss[10]={1,2,3,5,7,11,13,17,19,23};
 6 
 7 void DFS(LL now,int cnt,int tot)
 8 {
 9     if(cnt>9) return ;
10     if(tot>tmp)
11     {
12         tmp=tot;
13         ans=now;
14     }
15     if(tot==tmp&&ans>now) ans=now;
16     for(LL i=1; i<=30; ++i)
17     {
18         if(now*ss[cnt]>n) return ;
19         DFS(now*ss[cnt],cnt+1,tot*(i+1));
20         now*=ss[cnt];
21     }
22 }
23 
24 int AC()
25 {
26     scanf("%lld",&n);
27     DFS(1,0,1);
28     printf("%lld",ans);
29     return 0;
30 }
31 
32 int Aptal=AC();
33 int main(){;}
——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
原文地址:https://www.cnblogs.com/Shy-key/p/7507175.html