计算小于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的更多相关文章

  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. Xenia and Divisors

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

  4. hihocoder1187 Divisors

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...

  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. 如何使官方提供的AppRTCDemo 运行在自己搭建的server(官方提供的apprtc)上(官方的server源码)

    原文转自 http://stackoverflow.com/questions/21085261/apprtcdemo-with-local-server-works-between-browsers ...

  2. Spring 定时任务2

    转载自http://www.cnblogs.com/nick-huang/p/4864737.html > 版本说明 <dependencies> <dependency> ...

  3. signtool

    https://msdn.microsoft.com/en-us/library/8s9b9yaz(v=vs.110).aspx C:\Users\Administrator\.nuget\packa ...

  4. 8 个必备的PHP功能开发

    做过PHP开发的程序员应该清楚,PHP中有很多内置的功能,掌握了它们,可以帮助你在做PHP开发时更加得心应手,本文将分享8个开发必备的PHP功能,个个都非常实用,希望各位PHP开发者能够掌握.    ...

  5. (原创)LAMP搭建之一:图解如何安装并检查LAMP

    LAMP搭建之一:图解如何安装并检查LAMP 第一步:安装Linux(RedHat5) 第二步:rpm -qa httpd(查看apache是否安装) rpm -qa php(查看php是否安装) r ...

  6. window.location.href 失效的解决办法

    第一种:在window.location.href 后面加上 window.event.returnValue = false; 如: <a href="#" onclick ...

  7. 20161026__Oracle10g_DataGuard

    1. orcl.__db_cache_size=180355072 orcl.__java_pool_size=4194304 orcl.__large_pool_size=4194304 orcl. ...

  8. 获得省市 json 后台代码

    string connString = ConfigurationManager.ConnectionStrings["connStr"].ToString(); SqlConne ...

  9. spm总结

    自己尽量做出来,不要等和依靠,发挥主观能动性,所有的配置都在features模块里,一个一个的慢慢找和点击查找

  10. 最精简的django程序

    一.程序框架 1.结构图