题目地址
证明书上有 P141(算法进阶指南)。
记录代码:
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define int long long
#define sc scanf
#define pf printf
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 998244353;
const int N = 1000010;
int primes[] = {2,3,5,7,11,13,17,19,23,29};
int ma = 0,n,ans = INF;
// u当前是哪个素数下标,last上一个素数的最大次数,cnt约数个数,tol次数之和,sum,所求值
void dfs(int u,int sum,int last,int cnt,int tol){
if(u == 10){
if(cnt == ma) ans = min(ans,sum);
else if(cnt > ma) ma = cnt,ans = sum;
return ;
}
for(int i=0;i<=last;i++){//0开始
if(tol + i > 30 || sum > n) break;
dfs(u+1,sum,i,cnt*(i+1),tol + i);
sum *= primes[u];
}
}
signed main(){
// IOS;
#ifdef ddgo
freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
#endif
cin>>n;
dfs(0,1,30,1,0);
cout<<ans<<endl;
return 0;
}