More Divisors ZOJ
来源:互联网 发布:推荐书籍知乎 编辑:程序博客网 时间:2024/06/06 20:23
Everybody 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
100
Sample Output:
6
12
60
知道反素数的性质即可,然后dfs
#include <iostream>#include <string.h>#include <stdio.h>using namespace std;int p[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};long long maxNum;int num;long long n;void dfs(int cur,long long temp,int total,int limit){ if(temp>n) return; if(total>num) { num=total; maxNum=temp; } if(total==num&&maxNum>temp) maxNum=temp; long long cal=temp; for(int i=1;i<=limit;i++) { cal*=p[cur]; if(cal>n) return; dfs(cur+1,cal,total*(i+1),i); }}int main(){ while(scanf("%lld",&n)==1) { maxNum=1; num=1; dfs(0,1,1,54); cout<<maxNum<<endl; } return 0;}
- zoj 2562 More Divisors
- Zoj 2562 More Divisors
- zoj 2562 More Divisors
- zoj 2562 More Divisors
- ZOJ-More Divisors
- 【ZOJ 2562】 More Divisors
- More Divisors ZOJ
- More Divisors ZOJ
- zoj 2562 More Divisors(反素数)
- Zoj 2562 More Divisors (反素数)
- zoj 2562 More Divisors(反素数)
- ZOJ 2562 More Divisors 反素数 DFS
- ZOJ More Divisors 2562 (反素数)
- ZOJ 2562 More Divisors 解题报告(反素数)
- ZOJ 2562 More Divisors(高合成数)
- ZOJ Problem Set - 2562 More Divisors 反素数
- More Divisors----反素数
- zoj2562 More Divisors
- 关于jquery的obj.click()、和obj.on()以及行内的onclick事件
- HDU1248 寒冰王座
- VSCode中emmet被自动提示覆盖问题
- HDU 6004 Periodical Cicadas(拓展欧几里得+预处理)
- apt/yum/rpm/dpkg 使用总结
- More Divisors ZOJ
- js的数据类型
- RGBA、YUV色彩格式及libyuv的使用
- 未知:密码——题解
- mysql使用sql语句同步数据
- 对测试驱动开发的一些理解
- Excel在统计分析中的应用—第一章—统计基础与数据描述
- iOS 10以后访问权限设置
- Oracle的基本数据字典