博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

反素数

题目: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

 

 

 

posted @ 2019-03-01 18:57  GUET_uzi  阅读(130)  评论(0编辑  收藏  举报

- 创建于 2018年9月1日

这是一位ACM爱好者&数学爱好者的个人站,内容主要是算法&数据结构&数学研究的技术文章,大部分来自学习,部分来源于网络,希望对大家有所帮助。