CF27E
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <vector>
#include <unordered_map>
#define LOCAL
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define PII pair<int, int>
#define PDI pair<double, int>
#define int long long
#define ll long long
#define ull unsigned long long
#define debug(a) cout << #a << "=" << a << endl;
#define all(x) (x).begin(), (x).end()
#define sd(x) scanf("%d", &(x))
#define sddd(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
using namespace std;
const int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
int n, ans = INF;
//反素数dfs:
//1.dfs(当前选到了哪个素数, 当前的乘积, 当前约数的个数, 当前的素数最多能选多少个)
//2.枚举每一层能选多少个素数
//3.如果当前的素数超出范围了,return
//4.如果当前的乘积大于答案了,return
//5.如果当前的约数个数大于n了,return
//6.如果当前的约数个数刚好满足,更新答案
//dfs指数型枚举+剪枝=组合型枚举
//这题是dfs排列型枚举
void dfs(int dep, int temp, int num, int up) {
if (dep >= 16 || temp > ans)
return;
if (num == n && temp < ans) {
ans = temp;
return;
}
for (int i = 1; i <= up; ++i) {
if (ans / prime[dep] < temp)
break;
dfs(dep + 1, temp = temp * prime[dep], num * (i + 1), i);
}
}
signed main() {
#ifdef LOCAL
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
IOS;
cin >> n;
dfs(0, 1, 1, 60);
cout << ans << '\n';
}
?
|