ZOJ 2562 More Divisors(高合成数)

ACM

题目地址:ZOJ 2562 More Divisors

题意: 

求小于n的最大的高合成数,高合成数指一类整数,不论什么比它小的自然数的因子数目均比这个数的因子数目少。

分析: 

网上都叫它反素数,事实上我查了一下,翻素数应该是正着写倒着写都是素数的素数。这个应该叫高合成数,见Wikipedia: Highly composite number

高合成数有下面特征: 

where p1<p2<⋯<pk are
prime, and the exponents ci are
positive integers. 

Any factor of n must have the same or lesser multiplicity in each prime: 

p1^d1×p2^d2×⋯×pk^dk, 0≤di≤ci, 0<i≤k 

所以用回溯枚举。

代码:

/*
* Author: illuz <iilluzen[at]gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: 2562.cpp
* Create Date: 2014-08-06 20:45:53
* Descripton: Highly Composite Number
*/ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define repf(i,a,b) for(int i=(a);i<=(b);i++) typedef long long ll; const int M = 1000; ll n;
ll bestNum;
ll bestSum;
ll hcm[M][2];
ll prim[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67}; // current is num, use the prim[k], sum of divisors, the limit of prim[k] you can use
void getNum(ll num, int k, ll sum, int limit) {
if (sum > bestSum) {
bestSum = sum;
bestNum = num;
} else if (sum == bestSum && num < bestNum) {
bestNum = num;
} ll p = prim[k];
for (int i = 1; i <= limit; i++, p *= prim[k]) { // use i prim[k]s
if (num * p > n) break;
getNum(num *= prim[k], k + 1, sum * (i + 1), i);
}
} // clac log2(n)
int log2(ll n) {
int ret = 0;
ll p = 1;
while (p < n) {
p <<= 1;
ret++;
}
return ret;
} // return the number of Highly Composite Number in [1, n]
// and save the HCM in hcm[][2]
int gethcm() {
int ret = 0;
n = 500000; // [1, n]
while (n > 0) {
bestNum = 1;
bestSum = 1;
getNum(1, 0, 1, log2(n));
cout << bestNum << ' ' << bestSum << endl; hcm[ret][0] = bestNum;
hcm[ret][1] = bestSum;
n = bestNum - 1;
ret++;
}
return ret;
} int main() {
while (cin >> n) {
bestNum = 1;
bestSum = 1;
getNum(1, 0, 1, 50);
cout << bestNum << endl;
}
}

ZOJ 2562 More Divisors(高合成数)的更多相关文章

  1. ZOJ 2562 More Divisors

    又是个水题,刚刚开始没有用搜索,因为对于反素数有: n=2^t1*3^t2^5^t3*7^t4..... 这里有 t1>=t2>=t3>=t4. 而且相同的因数的情况下,素数越不同越 ...

  2. ZOJ 2562 HDU 4228 反素数

    反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...

  3. zoj 2562 反素数

    题目大意:求n范围内最大的反素数(反素数定义:f(x)表示x的因子数,f(x)>f(x1) (0<x1<x)) x用质因数形式为:x=a1^p1*a2^p2......an^pn(a ...

  4. ACM数学

     1.burnside定理,polya计数法 这个专题我单独写了个小结,大家可以简单参考一下:polya 计数法,burnside定理小结 2.置换,置换的运算 置换的概念还是比较好理解的,< ...

  5. [BZOJ]3737 [Pa2013]Euler

    从这个FB开始写博客啦. 也不知道会坚持多久…… = =似乎要加一句转载请注明出处 http://www.cnblogs.com/DancingOnTheTree/p/4026076.html htt ...

  6. poj 2886 线段树的更新+反素数

    Who Gets the Most Candies? Time Limit: 5000 MS Memory Limit: 0 KB 64-bit integer IO format: %I64d , ...

  7. ZOJ- 2562 反素数使用

    借用了下东北师大ACM的反素数模版. 本来我是在刷线段树的,有一题碰到了反素数,所以学了一下..有反素数的存在,使得一个x ,使得x的约数个数,在1 到 x的所有数里面,是最大的. 这里面还涉及安叔那 ...

  8. zoj 3762(求三角形的最大高)

    给出n个点,要你找到一个三角形,它的高是最长的. 思路:暴力超时了,是用先找出n个点与其他点的最长边,再枚举顶点过的.......具体证明不知道..... #include<algorithm& ...

  9. zoj 2286 Sum of Divisors

    // f(n)表示 n的约数和 不包括自己// 给你一个m 求1 到 100万里面 f(n)<=m 的个数// 那么首先要用筛选求出所有出 f(n)// 然后就好办了 // 写好后 看见别人好快 ...

随机推荐

  1. sheelエラー、オブジェクトを解析中にエラーが発生しました。

  2. Flink资料(3)-- Flink一般架构和处理模型

    Flink一般架构和处理模型 本文翻译自General Architecture and Process Model ----------------------------------------- ...

  3. c语言面试题(感觉比较好的题目)

    1.static全局变量与普通的全局变量有什么区别?static局部变量和普通局部变量有什么区别?static函数与普通函数有什么区别? 答:static全局变量--只在定义了该变量的源文件内有效,初 ...

  4. Open source and free log analysis and log management tools.

    Open source and free log analysis and log management tools. Maintained by Dr. Anton Chuvakin Version ...

  5. ANDROID SHAPE画圆形背景_ANDROID实现角标布局

    ANDROID SHAPE画圆形背景_ANDROID实现角标布局 <?xml version="1.0" encoding="UTF-8"?> &l ...

  6. COCOS2d-x简易安装步骤

    准备工作:1.    下载 cocos2d-x  下载地址:http://cdn.cocos2d-x.org/cocos2d-x-2.2.zip2.    下载 python 2.7.3 下载地址:h ...

  7. The Euler function(欧拉函数)

    The Euler function Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  8. winfrom播放动态图片

    winfrom是不能直接加载的动态图片的.只能够自己写方法实现. 具体代码如下: using System; using System.Collections.Generic; using Syste ...

  9. Win10下Genymotion无法正常使用的解决方法

    原Win7下安装配置的genymotion正常使用,Eclipse的Genymotion插件也可以正常运行.系统升级后,忽然就不work了. 折腾了一天试了各种方式,网上的例子也五花八门.最后还是找到 ...

  10. Deep Learning(深度学习)学习笔记整理系列之(四)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...