反素數(dfs)
阿新 • • 發佈:2021-02-10
技術標籤:演算法進階指南
#include<bits/stdc++.h> #define ll long long using namespace std; ll n; ll ans1=0,ans2=1e18; ll primes[10]={2,3,5,7,11,13,17,19,23,29}; void dfs(int u,int pre,ll sum,ll num){ if((num>ans1)||(num==ans1&&sum<ans2)){ ans1=num; ans2=sum; } if(u>9) return ; for(int i=1;i<=pre;i++){ if(sum*primes[u]>n) break; sum*=primes[u]; dfs(u+1,i,sum,num*(i+1)); } } int main(){ scanf("%lld",&n); dfs(0,31,1,1); printf("%lld\n",ans2); return 0; }