hihocoder1187 Divisors
描述
Given an integer n, for all integers not larger than n, find the integer with the most divisors. If there is more than one integer with the same number of divisors, print the minimum one.
输入
One line with an integer n.
For 30% of the data, n ≤ 103
For 100% of the data, n ≤ 1016
输出
One line with an integer that is the answer.
- 样例输入
-
100
- 样例输出
-
60
_______________________________________
Solution:
将正整数n进行质因数分解:
n = p1^k1 * p2^k2 * ... * pm^km
(p1 < p2 < ... < pm)
易见,n的因子数为
(1+k1)*(1+k2)*...*(1+km)
接下来考虑不超过N的正整数中,因子数最多且最小的数,记为s(N)。
我们可以推导出s(N)的质因数分解的形式有下列特征:
(1) s(N) = 2^k1 * 3^k2 * 5^k3 * ...* p[i]^ki * ... *p[m]^km
式中p[i]表示第i个质数。
(2) k1 <= K2 <= k3 <= ... <=km
可概括为:
(1)质因子连续
(2)指数单调不增
因此可采取暴力搜索(DFS)的办法求解。
————————————————————————————————————
Complexity:
前14个质数的乘积为 13082761331670030 ~ 1.3E16
所以搜索层数最多为13层,复杂度可大胆估计为2^13,这里不需要估计得比较准确。
————————————————————————————————————————————————————————————
Implementation:#include <bits/stdc++.h>
using namespace std;
typedef long long LL; const int N();
bool p[N];
int P[N];
int np; void seive(int n){
memset(p, , sizeof(p));
p[]=p[]=;
for(int i=; i<=n; i++){
if(p[i]) P[np++]=i;
for(int j=i<<; j<=n; j+=i)
p[j]=;
}
} LL ans, val, n; void dfs(int lev, LL res, int cnt, LL v){
if(v*P[lev]>n){
if(res>ans){
ans=res;
val=v;
}
else if(res==ans&&val>v)
val=v;
}
else{
for(int i=; v*P[lev]<=n&&i<=cnt; i++){
v*=P[lev];
dfs(lev+, res*(i+), i, v);
}
}
} int main(){
seive();
cin>>n;
val=n;
dfs(, , , );
cout<<val<<endl;
}
hihocoder1187 Divisors的更多相关文章
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- HDU - The number of divisors(约数) about Humble Numbers
Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...
- Divisors
计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...
- Xenia and Divisors
Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
- UVa 294 (因数的个数) Divisors
题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...
- hdu4432 Sum of divisors(数论)
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- 实现Maya FEM节点
准备实现FEM节点. 发现一种让自定义的Locator以及它的变换节点自动命名的方法.代码如下: void FEMSimulationNode::postConstructor() { MFnDepe ...
- nvl函数
NVL(E1, E2)的功能为:如果E1为NULL,则函数返回E2,否则返回E1本身. 但此函数有一定局限,所以就有了NVL2函数. NVL2(E1, E2, E3)的功能为:如果E1为NULL,则函 ...
- mysql数据库的备份和导入
mysqldump -u root -p --default-character-set = gbk -d demo_db>c:/appserv/www/demosql/sql1.sql//将数 ...
- JS 浮点数运算丢失精度解决方案
除法 function accDiv(arg1,arg2){ var t1=0,t2=0,r1,r2; try{t1=arg1.toString().split(".")[1].l ...
- 分布式监控系统Zabbix-3.0.3-完整安装记录(5)-邮件报警部署
前面几篇陆续介绍了zabbix3.0.3监控系统的部署和监控项配置,今天这里分享下zabbix3.0.3的邮件报警的配置过程~由于采用sendmail发送邮件,常常会被认为是垃圾邮件被拒,所以不推荐这 ...
- 工作者队列原理解析(后台writeback)
每一个CPU都会有两个(或者一个?)kwoker线程. kwoker线程,说白了就是尽量减少进程的数目,为了什么呢?因为线程数据太多的话,调度的成本比较高,占用太多的系统资源,所以这里是进程的一个简化 ...
- 12Spring_AOP编程(AspectJ)_前置通知
接下里的博客会一篇一篇的讲解每一个通知.其实AOP_AspectJ的编程与传统的AOP的编程的最大的区别就是写一个Aspect 支持多个Advice和多个PointCut .而且我们写AOP_Aspc ...
- Linux 网络编程八(epoll应用--大并发处理)
//头文件 pub.h #ifndef _vsucess #define _vsucess #ifdef __cplusplus extern "C" { #endif //服务器 ...
- SQL SERVER with递归示例一则
WITH SUBQUERY AS ( SELECT ORGID FROM OM_ORGANIZATION WHERE PARENTORGID = 'ROOT' UNION ALL SELECT B.O ...
- 即学即会 Java 程序设计基础视频教程(100课整)无水印版
课程总共包含100个课时,总授课长达27多个小时,内容覆盖面广,从入门到精通,授课通俗易懂,分析问题独到精辟通过本套视频的学习,学员能够快速的掌握java编程语言,成为java高手. 课程目录:课时1 ...