传送门

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Divisors

    计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...

  4. Xenia and Divisors

    Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  6. Sum of divisors

    Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...

  7. 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 ...

  8. UVa 294 (因数的个数) Divisors

    题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...

  9. hdu4432 Sum of divisors(数论)

    Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. sublime text2 常用快捷键

    1. ctrl+方向键  按单词移动 2. ctrl+shift + 方向键  按单词选取 3. ctrl + F3 查找选定的或光标所在单词 4. F3 查找特定的单词(一般查找的流程是先ctrl+ ...

  2. ArcGis 统计方法

    from:http://blog.sina.com.cn/s/blog_4177d50b0100fjbg.html 概述 一般常用的统计功能例如:唯一字段统计.数据行数统计.数据值求和统计等. 1.基 ...

  3. sqlserver字段类型详解(转)

    bit    整型 bit数据类型是整型,其值只能是0.1或空值.这种数据类型用于存储只有两种可能值的数据,如Yes 或No.True 或False .On 或Off. 注意:很省空间的一种数据类型, ...

  4. MySQL基础 - mysql命令行客户端

    在Linux系统当中,mysql作为一个客户端命令程序,在很大程度上连接数据库都是使用mysql,因此很有必要熟悉mysql命令行的使用. 这里假设数据库用户为icebug,密码为icebug_pas ...

  5. HTTP基础(一):如何使用浏览器network查看请求和响应的信息

    一. 问题描述 HTTP作为前端开发与后开发链接的载体,其重要性不言而喻,今天我不复习关于HTTP自身的一些知识,只复习如何解读浏览器自带的的抓包工具(查看请求信息与响应信息)network. 二. ...

  6. NET中MSMQ的使用----附例子

    目录 一:MSMQ的一些理论上的知识 二:队列类型(Queue Type) 三:安装消息队列 四:在C#中Messagequeue class 五:MSMQ-发送消息到远程专用队列 六:例子   一. ...

  7. SVM+HOG特征训练分类器

    #1,概念 在机器学习领域,支持向量机SVM(Support Vector Machine)是一个有监督的学习模型,通常用来进行模式识别.分类.以及回归分析. SVM的主要思想可以概括为两点:⑴它是针 ...

  8. 一款漂亮实用的Android开源日期控件timessquare

    这个开源控件可以兼容到SDK8版本,可以自定义显示的年月日,以及时间范围,如图 如果我们只想显示两个月的日期选择区间: final Calendar month = Calendar.getInsta ...

  9. Android强制弹出,隐藏输入法.

    当我们弹出一个Dialog时候,如果这个Dialog需要输入数据,然后确定后又需要关闭输入法,一般系统的hide,跟show方法总会有各种问题,最霸道的解决方法就是写一个定时器,定时弹出或者关闭输入法 ...

  10. Linux及安全——ELF实践

    Linux及安全——ELF实践  一.分析ELF文件头 二.通过文件头找到section header table,理解内容 三.通过section header table 找到各section 四 ...