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) ...
随机推荐
- 怎么解决Android studio导入项目卡死
在使用Android studio的时候常常遇到这样的问题,从github或是其他地方导入项目,Android studio呈现卡死的现象!当遇到这种情况时,可以看看是下面那种情况,在按照方法来解决! ...
- Ember模板中的操作指向
模板中的链接操作指向有三个地方,该模板对应的控制器和路由以及视图,默认是先跳转到控制器,如果控制器里没有定义模板中动作的方法,就去该模板对应的路由里找,如果还没找到,就去父级路由找,直到顶级路由,如果 ...
- linux下正向代理/反向代理/透明代理使用说明
代理服务技术对于网站架构部署时非常重要的,一般实现代理技术的方式就是在服务器上安装代理服务软件,让其成为一个代理服务器,从而实现代理技术.常用的代理技术分为正向代理.反向代理和透明代理.以下就是针对这 ...
- 如何在.net4.0中使用.net4.5的async/await
推荐文章: http://www.cnblogs.com/hj4444/p/3857771.html http://www.cnblogs.com/dozer/archive/2012/03/06/a ...
- 多线程BackgroundWorker
链接:http://www.cnblogs.com/yiyisawa/archive/2008/11/24/1339826.html 周六闲来无事,学习了多线程BackgroundWorker,以此记 ...
- Delphi7 安装ICS,与简单使用
官网 http://www.overbyte.be/ 下载 OverbyteIcsV816 完成后解压到E:\Delphi7\OverbyteIcsV816\ 1.在library里加入E:\Delp ...
- [转]Hive/Beeline 使用笔记
FROM : http://www.7mdm.com/1407.html Hive: 利用squirrel-sql 连接hive add driver -> name&example u ...
- 检查c# 内存泄漏
c# 内存泄漏检查心得 系统环境 windows 7 x64 检查工具:ANTS Memory Profiler 7 或者 .NET Memory Profiler 4.0 开发的软件为winform ...
- react native 布局注意点
一.react native中很多是ES6语法. 1行.表示是js的严格模式. 'use strict';严格模式中变量必须先声明,然后赋值.定义等:还有就是this的绑定. 2行到8行.导入依赖,可 ...
- Linux考试易忘命令
这是为了考试而做的笔记 mv命令可以移动可以改名 mv a /test //移动a到test文件夹下 mv a b //把a改名为b 软链接和硬链接的创建 ln -s profile a //prof ...