反素数

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

题意:给一个数,求一个最小的正整数,使得它的因子个数为

 

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4  
 5 using namespace std;
 6 typedef unsigned long long ULL;
 7 const ULL INF = ~0ULL;
 8  
 9 int p[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
10  
11 int n;
12 ULL ans;
13  
14 void dfs(int dept,ULL tmp,int num)
15 {
16     if(num > n) return;
17     if(num == n && ans > tmp) ans = tmp;
18     for(int i=1;i<=63;i++)
19     {
20         if(ans / p[dept] < tmp) break;
21         dfs(dept+1,tmp *= p[dept],num*(i+1));
22     }
23 }
24  
25 int main()
26 {
27     while(cin>>n)
28     {
29         ans = INF;
30         dfs(0,1,1);
31         cout<<ans<<endl;
32     }
33     return 0;
34 }
View Code

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1562

题意:求以内的因子最多的那个数。

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4  
 5 using namespace std;
 6 typedef unsigned long long ULL;
 7 const ULL INF = ~0ULL;
 8  
 9 int p[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
10  
11 ULL ans,n;
12 int best;
13  
14 void dfs(int dept,ULL tmp,int num)
15 {
16     if(dept >= 16) return;
17     //num记录的因子个数,如果遇到更小的,就更新
18     if(num > best)
19     {
20         best = num;
21         ans = tmp;
22     }
23     //当因子个数相同时,取值最小的
24     if(num == best && ans > tmp) ans = tmp;
25     for(int i=1;i<=63;i++)
26     {
27         if(n / p[dept] < tmp) break;
28         dfs(dept+1,tmp *= p[dept],num*(i+1));
29     }
30 }
31  
32 int main()
33 {
34     while(cin>>n)
35     {
36         ans = INF;
37         best = 0;
38         dfs(0,1,1);
39         cout<<ans<<endl;
40     }
41     return 0;
42 }
View Code

 

 

 

转载于:https://www.cnblogs.com/zxz666/p/10458245.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值