Codeforces Beta Round #27-E. Number With The Given Amount Of Divisors

来源:互联网 发布:下载宇龙汽修仿真软件 编辑:程序博客网 时间:2024/06/01 09:49

原题链接

E. Number With The Given Amount Of Divisors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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 divisors.

Examples
input
4
output
6
input
6
output
12

这道题的求解方法和求反素数相同

#include <bits/stdc++.h>#define INF 1e18using 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;}


0 0
原创粉丝点击