E. Number With The Given Amount Of Divisors
time limit per test
memory limit per test
input
output
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactly n
Examples
input
4
output
6
input
6
output
12
这道题的求解方法和求反素数相同
#include <bits/stdc++.h>
#define INF 1e18
using namespace std;
typedef long long ll;
int p[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
ll ans = INF;
int n;
void dfs(int depth, ll temp, int num){
if(num == n && ans > temp){
ans = temp;
return ;
}
for(int i = 1;; i++){
if(ans / p[depth] < temp|| (num*(i+1)) > n)
break;
dfs(depth+1, temp *= p[depth], num*(i+1));
}
}
int main(){
scanf("%d", &n);
dfs(0, 1, 1);
cout << ans << endl;
return 0;
}