思路:建树搜索,以每一个pi为一层建树搜索。
#include
#include
#include
using namespace std;
#define ll long long
const ll maxm = 1e18;
ll ans, n;
int prime[10] = { 2,3,5,7,11,13,17,19,23,29 };
void dfs(int a, int b, ll temp);
int main()
{
while (scanf("%d", &n) != EOF)
{
ans = maxm;
dfs(1, 0, 1);
printf("%I64d\n", ans);
}
return 0;
}
void dfs(int a, int b, ll temp)
{
if (a == n&&ans >= temp)
ans = temp;
if (a >= n)
return;
for (int i = 1;i <= 64;i++)
{
if (ans / prime[b] < temp)
break;
temp *= prime[b];
dfs(a*(i + 1), b + 1, temp);
}
}
#include
#include
#include
#include
using namespace std;
#define ll long long
const int ll maxm = ~0ULL;
ll n, ans, sum = 0;
int p[16] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53 };
void dfs(int a, int b, ll temp);
int main()
{
while (cin >> n)
{
ans = maxm;
sum = 0;
dfs(1, 0, 1);
cout << ans << endl;
}
return 0;
}
void dfs(int a, int b, ll temp)
{
if (b >= 16)
return;
if (a >= sum)
{
if (a > sum)
{
sum = a;
ans = temp;
}
else if (a == sum&&temp < ans)
ans = temp;
}
for (int i = 1;i <= 64;i++)
{
if (temp*p[b] > n)
break;
temp *= p[b];
dfs(a*(i + 1), b + 1, temp);
}
}