Codeforeces 27 E Number With The Given Amount Of Divisors(反素数)

来源:互联网 发布:linux 安装jdk gz 编辑:程序博客网 时间:2024/06/06 07:28

题目链接:
Codeforeces 27 E Number With The Given Amount Of Divisors
题意:
给出n找到最小的数使得其约数个数恰为n

#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <climits>#include <cmath>#include <ctime>#include <cassert>#define IOS ios_base::sync_with_stdio(0); cin.tie(0);using namespace std;typedef long long ll;typedef unsigned long long lint;const lint inf = ~0ull;const int prime[]= {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};int n;lint ans;void dfs(int depth, int limit, lint tmp, int num){    if(num > n) return;    if(num == n && tmp < ans) ans = tmp;    for(int i = 1; i <= limit; ++i) { //i相当于幂次        if(tmp * prime[depth] > ans) break; //不用扩展树的深度        tmp *= prime[depth];        if(n % (num * (i + 1)) == 0) {             dfs(depth + 1, i, tmp, num * (i + 1));        }    }}int main(){    while(cin >> n){        ans = inf;        dfs(0, 63, 1, 1);        cout << ans << endl;    }    return 0;}
0 0