CF--27E(反素数)

2014-09-30 22:29:59

(参考)推荐博客:http://blog.csdn.net/ACdreamers/article/details/25049767

思路:做到poj2886,顺便刷了这题来学一下反素数。如何遍历一个数的所有因子呢?大致思路:首先看这个数的唯一素数分解式,如:n = p1^k1 * p2 * k2 * ... * pm^km,那么根据每个素因子pi,构建出DFS树的一层,如图,然后DFS,详情的话看我推荐的博客把~

 1 /*************************************************************************
 2     > File Name: e.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Tue 30 Sep 2014 09:45:55 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <queue>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17 #define lpos (pos << 1)
18 #define rpos (pos << 1|1)
19 #define getmid(l,r) (l + (r - l) / 2)
20 typedef long long ll;
21 const ll INF = (ll)1 << 62;
22 
23 int n;
24 int prime[20] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
25 ll ans;
26 
27 void Dfs(int dep,int num,ll val){
28     if(num > n) return;
29     if(num == n && val < ans){
30         ans = val;
31         return;
32     }
33     for(int i = 1; i <= 60; ++i){
34         if(ans / prime[dep] < val) break; //剪枝
35         Dfs(dep + 1,num * (i + 1),val *= prime[dep]);
36     }
37 }
38 
39 int main(){
40     //ios::sync_with_stdio(false);
41     cin >> n;
42     ans = INF;
43     Dfs(0,1,1);
44     cout << ans << endl;
45     return 0;
46 }

 

转载于:https://www.cnblogs.com/naturepengchen/articles/4002772.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值