Divisors
计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数。
http://hihocoder.com/problemset/problem/1187
对于100有 60 = 2 * 2 * 3 * 5,共 (2 + 1) * (1 + 1) * (1 + 1) = 12个约数。
对于 n <= 10 ^ 16,int最大值为10位,所以这里要用long long。很显然:约数要尽量小,然后小的约数的指数一定大于大的约数的指数。
所以对于 10^16,有质因子:2,3,5,7,11,13,17,19,23,29,31,37,41,43,47...后面的可以不考虑了。
#include <cstdio>
#include <cmath> int p[] = {, , , , , , , , , , , , , , };
long long n, result = << ;
int maxDivisors = ; void dfs(long long res, int divisors, int np, int ti) {
if (np > || res > n) return;
if (divisors > maxDivisors || (divisors == maxDivisors && res < result)) {
maxDivisors = divisors;
result = res;
}
int t = p[np];
int i = ;
long long val;
while ((val = res * std::pow(t, i)) < n && i <= ti) {
dfs(val, divisors * (i + ), np + , i);
++i;
}
} int main() {
scanf("%lld", &n);
dfs(, , , );
printf("%lld\n", result);
return ;
}
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 ...
- Xenia and Divisors
Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- hihocoder1187 Divisors
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...
- 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) ...
随机推荐
- PDO处理大批量数据的入库
<?php //最东端 东经135度2分30秒 //最西端 东经73度40分 //最南端 北纬3度52分 //最北端 北纬53度33分 //转换为度的单位$dbName = 'txhl';//数 ...
- 查看oracle被锁的表
SELECT /*+ rule*/ a.sid, b.owner, object_name, object_type FROM v$lock a, all_objects b WHERE TYPE = ...
- Reflection
Reflection 反射能在运行时获取一个类的全部信息,并且可以调用类方法,修改类属性,创建类实例. 而在编译期间不用关心对象是谁 反射可用在动态代理,注解解释,和反射工厂等地方. -------- ...
- 史上最"恐怖"的12生肖图,绝对超猛
史上最“恐怖”的十二生肖图,绝对超猛!图片依次是:鼠 牛 虎 兔 龙 蛇 马 羊 猴 鸡 狗 猪!
- UVa 12299 RMQ with Shifts(移位RMQ)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: "Times New ...
- svn server
svn server: 1.c:\Program Files\TortoiseSVN\bin>svnserve -d -r C:\Jasper\Repositories2.change the ...
- RMAN的恢复篇
Oracle 数据库的恢复实际上包含了两个概念:数据库修复(RESTORE)与数据库恢复(RECOVER): 数据库修复:是指利用备份的数据库文件来替换已经损坏的数据库文件或者将其恢复到一个新的位置. ...
- 启动tomcat后struts框架报异常严重: Exception starting filter struts2 Unable to load configuration.
启动tomcat后struts框架报异常严重: Exception starting filter struts2 Unable to load configuration. 出现此异常是因为,str ...
- 数据库 基础篇2(mysql)
2.1MySQL入门 1)到mysql官网下载. 2)安装mysql软件 3)使用 验证是否成功 打开cmd -> 输入 mysql -u root -p 回车 -> 输入密码 ...
- Gulp Babel AMD转换例子
1.gulpfile.js var gulp = require('gulp'); const babel = require('gulp-babel'); gulp.task('default', ...