ZOJ 2562 More Divisors(高合成数)
ZOJ 2562 More Divisors(高合成数)
ACM
题意:
求小于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(高合成数)的更多相关文章
- ZOJ 2562 More Divisors
又是个水题,刚刚开始没有用搜索,因为对于反素数有: n=2^t1*3^t2^5^t3*7^t4..... 这里有 t1>=t2>=t3>=t4. 而且相同的因数的情况下,素数越不同越 ...
- ZOJ 2562 HDU 4228 反素数
反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...
- zoj 2562 反素数
题目大意:求n范围内最大的反素数(反素数定义:f(x)表示x的因子数,f(x)>f(x1) (0<x1<x)) x用质因数形式为:x=a1^p1*a2^p2......an^pn(a ...
- ACM数学
1.burnside定理,polya计数法 这个专题我单独写了个小结,大家可以简单参考一下:polya 计数法,burnside定理小结 2.置换,置换的运算 置换的概念还是比较好理解的,< ...
- [BZOJ]3737 [Pa2013]Euler
从这个FB开始写博客啦. 也不知道会坚持多久…… = =似乎要加一句转载请注明出处 http://www.cnblogs.com/DancingOnTheTree/p/4026076.html htt ...
- poj 2886 线段树的更新+反素数
Who Gets the Most Candies? Time Limit: 5000 MS Memory Limit: 0 KB 64-bit integer IO format: %I64d , ...
- ZOJ- 2562 反素数使用
借用了下东北师大ACM的反素数模版. 本来我是在刷线段树的,有一题碰到了反素数,所以学了一下..有反素数的存在,使得一个x ,使得x的约数个数,在1 到 x的所有数里面,是最大的. 这里面还涉及安叔那 ...
- zoj 3762(求三角形的最大高)
给出n个点,要你找到一个三角形,它的高是最长的. 思路:暴力超时了,是用先找出n个点与其他点的最长边,再枚举顶点过的.......具体证明不知道..... #include<algorithm& ...
- zoj 2286 Sum of Divisors
// f(n)表示 n的约数和 不包括自己// 给你一个m 求1 到 100万里面 f(n)<=m 的个数// 那么首先要用筛选求出所有出 f(n)// 然后就好办了 // 写好后 看见别人好快 ...
随机推荐
- English interview!
Q1:Why are you interested in working for our company?为什么有兴趣在我们公司工作?A1:Because your company has a goo ...
- [推荐] 查看网站使用的JS框架
查看各大网站使用的JS框架: 打开:http://oskarkrawczyk.github.com/wtframework/ 在这个中间的图片页面上右击,Add BookMarks.(添加到书签中) ...
- Windows 7 with SP1简体中文旗舰版(微软MSDN原版)+ 激活密钥
在Windows 7六个版本中,旗舰版和企业版功能性能完全一样,同属诸版本之中的最高版本.现提供Windows 7 with SP1简体中文旗舰版(微软MSDN最新原版)+ 激活密钥如下: 32位版本 ...
- Http 请求头中的 Proxy-Connection
平时用 Chrome 开发者工具抓包时,经常会见到 Proxy-Connection 这个请求头.之前一直没去了解什么情况下会产生它,也没去了解它有什么含义.最近看完<HTTP 权威指南> ...
- [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(五)
目的: 1. 了解PCI的基本知识,为完成watchdog的设备做准备. 准备知识: 简单的说,PCI 设备分3个空间. 配置空间,IO空间,内存地址空间. PCI设备厂家决定了外设是使用IO空间还是 ...
- centos ldap
Standalone LDAP Daemon, slapd(standalone lightweight access protocol)Lightweight Directory Access Pr ...
- NET-A-PORTER为何难以模仿?_全文显示_生活福布斯中文网
NET-A-PORTER为何难以模仿?_全文显示_生活福布斯中文网 NET-A-PORTER为何难以模仿?
- javascript编辑器预览模式解密
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Solrj日期范围查询
在做依据日期来检索的时候普通的格式化会出错,试了好多种仅仅有一种可行 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH ...
- 达内TTS6.0课件oop_day02