More Divisors(反素数)
2015-12-03 20:40
267 查看
More DivisorsTime Limit: 2 Seconds Memory Limit: 65536 KBEverybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is often not very convenient, ten has only four divisors -- 1, 2, 5 and 10. Thus, fractions like 1/3, 1/4 or 1/6 have inconvenient decimal representation. In this sense the notation with base 12, 24, or even 60 would be much more convenient.The main reason for it is that the number of divisors of these numbers is much greater -- 6, 8 and 12 respectively. A good quiestion is: what is the number not exceeding n that has the greatest possible number of divisors? This is the question you have to answer.Input:The input consists of several test cases, each test case contains a integer n (1 <= n <= 1016).Output:For each test case, output positive integer number that does not exceed n and has the greatest possible number of divisors in a line. If there are several such numbers, output the smallest one.Sample Input:
10 20 100Sample Output:
6 12 60 题解:找小于等于n的因子个数最大的最小整数; 代码:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<vector> #include<algorithm> using namespace std; const double PI=acos(-1.0); #define SI(x) scanf("%d",&x) #define SL(x) scanf("%lld",&x) #define PI(x) printf("%d",x) #define PL(x) printf("%lld",x) #define T_T while(T--) #define P_ printf(" ") typedef unsigned long long uLL; const uLL INF=(uLL)~0; int prim[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; uLL n,ans; int nn; void dfs(int pos,uLL v,int num){ if(num==nn)ans=min(ans,v); if(num>nn&&v<=n)nn=num,ans=v; for(int i=1;i<=63;i++){ if(v*prim[pos]>n)break; dfs(pos+1,v*=prim[pos],num*(i+1)); } } int main(){ while(~scanf("%llu",&n)){ nn=0;ans=INF; dfs(0,1,1); printf("%llu\n",ans); } return 0; }
相关文章推荐
- OpenCV&VS2010&Win7(64位)配置
- 从设备树的引入,能去分析的一些事
- poj 1743 Musical Theme 后缀数组da算法
- Laravel 单元测试
- cordova-plugin-app-version插件的使用以及注意的事项
- linux下kodi没有声音的解决
- 战争迷雾sharder
- 微服务架构-0
- 蒟蒻的入门之线段树
- 《Python程序设计》在亚马逊京东当当互动出版网淘宝全面上架
- Sql Server 表创建以及Ef浅谈
- ASPxGridView的几个使用方法
- ASPxGridview使用总结
- 四维空间的假想
- 物理内存、虚拟内存
- poj1338 Ugly Numbers
- 英语年份的读法
- iOS之UI随笔-UITableView的性能优化
- 表扩张
- [iOS] 使用CIColorCube快速製作濾鏡