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 , ...
随机推荐
- Linux驱动学习笔记(6)信号量(semaphore)与互斥量(mutex)【转】
转自:http://blog.chinaunix.net/uid-24943863-id-3193530.html 并发导致竟态,从而导致对共享数据的非控制访问,产生非预期结果,我们要避免竟态的发生. ...
- MAVEN修改localRepository不起作用
MAVEN修改localRepository不起作用 环境:win10 改用其他盘符都可以,唯独C:\Users\Administrator\.m2\repository不起作用,应该是win10权限 ...
- fork和exec一起使用
先预览一下工程的目录树: 实现的功能:master进程启动slave进程. 看看Makefile内容: all: master.out slave.out master.out: master.cpp ...
- jquery+thinkphp实现跨域抓取数据的方法
jquery的$.post发送数据到服务器后台,在由后台的PHP代码执行远程抓取,存到数据库ajax返回数据到前台,前台用JS接受数据并显示. //远程抓取获取数据$("#update_ac ...
- C#之参数线程
public Form1() { InitializeComponent(); } Thread t; private void button1_Click(object sender, EventA ...
- js格式化日期 年月日
/** * 格式化日期 * @param value * @param row ...
- 20150625_Andriod_02_ListView2_多条目显示_选中
android listview 参考地址: http://www.cnblogs.com/zhengbeibei/archive/2013/05/14/3078805.html http://xy ...
- The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏
The 3n + 1 problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53927 Accepted: 17 ...
- yum mysql on centos 7
参考:https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-centos-7 centos 7上没有办法使用yum i ...
- python 中time.sleep没有作用
很简单的一个程序: # -*- coding: utf-8 -*- import MySQLdb,os,json,time #from wsgiref.simple_server import mak ...