ZOJ-2562 More Divisors 反素数
题意:给定一个数N,求小于等于N的所有数当中,约数最多的一个数,如果存在多个这样的数,输出其中最大的一个。
分析:反素数定义:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4.如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数。
性质一:一个反素数的质因子必然是从2开始连续的质数。
性质二:p=2^t1*3^t2*5^t3*7^t4.....必然t1>=t2>=t3>=....
那题题目相当于求解小于等于N中,最大的反素数。搜索即可。这个搜索的速度是很快的。
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std; typedef long long LL; LL n;
vector<int>vp;
map<int,LL>mp; bool isprime(int x) {
if (x < ) return false;
if (x == ) return true;
int LIM = (int)sqrt(x);
for (int i = ; i <= LIM; ++i) {
if (x % i == ) return false;
}
return true;
} void pre() {
for (int i = ; i < ; ++i) {
if (isprime(i)) vp.push_back(i);
}
} void dfs(int p, int exp, int g, LL num) {
if (num * vp[p] > n) {
if (mp.count(g)) mp[g] = min(mp[g], num);
else mp[g] = num;
return;
}
num *= vp[p];
for (int i = ; num <= n && i <= exp; ++i, num *= vp[p]) {
dfs(p+, i, g*(i+), num);
}
} int main() {
pre();
while (scanf("%lld", &n) != EOF) {
mp.clear();
dfs(, , , );
printf("%lld\n", (--mp.end())->second);
printf("size = %d\n", mp.size());
}
return ;
}
ZOJ-2562 More Divisors 反素数的更多相关文章
- 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 More Divisors(高合成数)
ZOJ 2562 More Divisors(高合成数) ACM 题目地址:ZOJ 2562 More Divisors 题意: 求小于n的最大的高合成数,高合成数指一类整数,不论什么比它小的自然数 ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. 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 ...
- ZOJ 2562 More Divisors
又是个水题,刚刚开始没有用搜索,因为对于反素数有: n=2^t1*3^t2^5^t3*7^t4..... 这里有 t1>=t2>=t3>=t4. 而且相同的因数的情况下,素数越不同越 ...
- More Divisors(反素数)
More Divisors Time Limit: 2 Seconds Memory Limit: 65536 KB Everybody knows that we use decimal ...
- zoj 2562 反素数
题目大意:求n范围内最大的反素数(反素数定义:f(x)表示x的因子数,f(x)>f(x1) (0<x1<x)) x用质因数形式为:x=a1^p1*a2^p2......an^pn(a ...
- CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)
CodeForces - 27E Number With The Given Amount Of Divisors Submit Status Description Given the number ...
- zoj 1562 反素数 附上个人对反素数性质的证明
反素数的定义:对于不论什么正整数,其约数个数记为.比如,假设某个正整数满足:对随意的正整 数.都有,那么称为反素数. 从反素数的定义中能够看出两个性质: (1)一个反素数的全部质因子必定是从2開始的连 ...
- poj 2886 线段树的更新+反素数
Who Gets the Most Candies? Time Limit: 5000 MS Memory Limit: 0 KB 64-bit integer IO format: %I64d , ...
随机推荐
- XCode5 真机调试及发布应用
一.XCODE 真机测试 Xcode5已经很智能,只需生成一个开发证书,安装后,插入设备会自动添加,注意,当Mac系统升级后,证书需要重新生成. 证书生成步骤: 1.生成 CertificateSig ...
- HDU 3076:ssworld VS DDD(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD Problem Description One day, s ...
- hack是什么
不同浏览器对css的解析是不同是,因此需要css hack来解决浏览器局部的兼容性问题.针对不同浏览器写不同的CSS代码的过程叫CSS Hack. 常见的hack有三种形式,分别是CSS属性hack ...
- IE6下 input 背景图滚动问题及标签规范
ie6 背景图滚动问题: <title>ie6下input背景图滚动问题</title> <style> .box{ height:20px; width:300p ...
- c#委托之最大
public delegate int ceshi(object o1, object o2); static void Main(string[] args) { string[] a = { &q ...
- 【20160924】GOCVHelper综述
GOCVHelper(GreenOpen Computer Version Helper )是我在这几年编写图像处理程序的过程中积累下来的函数库.主要是对Opencv的适当扩展和在实现Mfc程序时候的 ...
- Python静态方法的使用
class Util(): @staticmethod def Func1(): print "Execute Func1!" def main(): Util.Func1()
- python Flask restful框架
框架地址:https://github.com/flask-restful/flask-restful 文档:http://flask-restful.readthedocs.io/en/0.3.5/ ...
- JAVA中生成Excel方法
java 操作 Excel 最常用的就是JXL(java excel api)和POI,今先看下JXL吧.首先可以到 http://www.andykhan.com/jexcelapi/downloa ...
- ci 基础知识
//建立虚拟主机 2.下载完毕后,解压,并将其复制粘贴到程序的主目录(d:/wamp/xmall/),然后再将其重命名为"myshop",那么"myshop" ...