传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1053
题意:对于任何正整数
题解: 实际要求的是不大于
1.答案的质因数分解一定是连续的前若干个质数。
2.答案的质因数分解指数从小到大递减
所以就变成了一个暴搜加两个剪枝。
#include<bits/stdc++.h>
int p[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
long long n, ans_num, ans;
void dfs(int dep, int last, long long num, long long now) {
if (now > n) return;
if (dep < 0) {if (num > ans_num || num == ans_num && now < ans) ans_num = num, ans = now; return;}
for (int i = 1; i <= last && now <= n; i++) now *= p[dep];
for (int i = last; now <= n; i++, now *= p[dep])
dfs(dep - 1, i, num * (i + 1), now);
}
int main() {
scanf("%lld", &n);
dfs(9, 0, 1, 1);
printf("%lld\n", ans);
return 0;
}