Codeforces 27E. Number With The Given Amount Of Divisors (暴力)

题目链接:http://codeforces.com/problemset/problem/27/E

暴力

 1 //#pragma comment(linker, "/STACK:102400000, 102400000")
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <cstdio>
 7 #include <vector>
 8 #include <cmath>
 9 #include <ctime>
10 #include <list>
11 #include <set>
12 #include <map>
13 using namespace std;
14 typedef long long LL;
15 typedef pair <int, int> P;
16 const int N = 1e5 + 5;
17 int a[20];
18 LL ans, p[] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29}, limit = 1e18;
19 
20 void dfs(int num, int len) {
21     if(num == 1) {
22         LL res = 1;
23         for(int i = 1; i <= len; ++i) {
24             for(int j = 1; j < a[i]; ++j) {
25                 if(limit / p[i] <= res) {
26                     return ;
27                 }
28                 res *= p[i];
29             }
30         }
31         ans = min(ans, res);
32         return ;
33     }
34     for(int i = 2; i <= num; ++i) {
35         if(num % i == 0) {
36             a[len + 1] = i;
37             dfs(num / i, len + 1);
38         }
39     }
40 }
41 
42 int main()
43 {
44     int n;
45     cin >> n;
46     if(n == 1) {
47         cout << 1 << endl;
48         return 0;
49     } else if(n == 2) {
50         cout << 2 << endl;
51         return 0;
52     }
53     ans = limit;
54     for(int i = 1; i <= n; ++i) {
55         if(n % i == 0) {
56             a[1] = i;
57             dfs(n/i, 1);
58         }
59     }
60     cout << ans << endl;
61     return 0;
62 }
原文地址:https://www.cnblogs.com/Recoder/p/5934638.html