BZOJ1053 反素数ant
我们先考虑唯一分解定理求出约数个数:
\(x=a_1^{p_1}a_2^{p_2}a_3^{p_3}...a_k^{p_k}\)
然后\(num=\Pi_{i=1}^k{p_i+1}\)
2,000,000,000中不同的素数因子大概是11个。
直接爆搜答案就好了。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define int ll
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
int f=1,sum=0;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
int prime[20]={0,2,3,5,7,11,13,17,19,23,29,31};
int n,ans=1,num=1;
void dfs(int now,ll sum,int use,int last){//last是最大的p
if(now==12){
if(sum>ans && use>num){ans=sum;num=use;}
else if(ans>=sum && use>=num){ans=sum;num=use;}
return;
}
int t=1;
for(int i=0;i<=last;i++){
dfs(now+1,sum*t,use*(i+1),i);
t*=prime[now];
if(1ll*t*sum>(ll)n)break;
}
}
main(){
scanf("%lld",&n);
dfs(1,1,1,31);
printf("%lld\n",ans);
return 0;
}