HYSBZ 1053 反质数
input
n 1<=n<=2000000000
output
不大于n的最大反质数
对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。
如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数。例如,整数1,2,4,6等都是反质数。
做法:直接打表查找
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#define MAX 100000
#define INF 2000000000
#define LL long long
int cas=,T,n,a[MAX],an,p[]={,,,,,,,,,};
struct node
{
int b[],n,v,g; //b数组是质数对应的次方,v是值,g是约数个数,n是质因子个数
bool operator<(node a)const { return v>a.v; }
};
void init()
{
std::priority_queue<node>q;
a[]=;an=;
int ming=;//当前最大的约数个数
node u;
u.v=;u.n=;u.b[]=;u.g=;
q.push(u);
while(!q.empty())
{
u=q.top();q.pop();
// printf("%d %d %d\n",u.v,u.g,u.n);
if(u.g>ming) { ming=u.g;a[an++]=u.v; }//比当前最大约数个数大的统计
else continue;
for(int i=;i<=u.n;i++)//出队后将每个质数对应的次方加一放进队列里
{
node v;
memcpy(&v,&u,sizeof(node));
LL tmp=(LL)v.v*p[i];
v.b[i]++;
v.g=v.g/v.b[i]*(v.b[i]+);
if(tmp<=INF) v.v=tmp;
if(tmp<=INF&&v.g>ming) q.push(v);
// printf("aaa:%d %d %d\n",v.v,v.g,v.n);
}
if(u.n+<)//增加一个质因子
{
node v;
memcpy(&v,&u,sizeof(node));
v.n++;v.b[v.n]=;v.g*=;
LL tmp=(LL)v.v*p[v.n];
if(tmp<=INF) v.v=tmp;
if(tmp<=INF&&v.g>ming) q.push(v);
}
}
a[an++]=INF+;
printf("%d\n",an);
for(int i=;i<an;i++) printf("%d,",a[i]);
}
int main()
{
//freopen("in","r",stdin);
//scanf("%d",&T);
init();
while(scanf("%d",&n)==) printf("%d\n",*(std::upper_bound(a,a+an,n)-));
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}
HYSBZ 1053 反质数的更多相关文章
- [bzoj]1053反质数<暴搜>
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1053 感想:这道题拿到以后还是想去知道一个数的约数个数要怎么求,去网上搜了公式,但是还是没有思 ...
- 反素数ant HYSBZ - 1053(数学+dfs)
对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x ,则称x为反质数.例如,整数1,2,4,6等都是反质 ...
- BZOJ 1053 - 反素数ant - [数论+DFS][HAOI2007]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 题解: 可以证明,$1 \sim N$ 中最大的反质数,就是 $1 \sim N$ ...
- BZOJ1053 [HAOI2007]反素数 & BZOJ3085 反质数加强版SAPGAP
BZOJ 1053 Description 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x ,则称x ...
- CNUOJ 0486 800401反质数
难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 将正整数 x 的约数个数表示为 g(x).例如,g(1)=1,g(4)=3, g ...
- 反质数问题,求不大于n的最大反质数
反质数:设f(n)表示n个约数的个数,如果对于任意x有0<x<n, f(x) < f(n),那么n就是一个反质数 我们都知道对于任意一个数n,都可以用质数乘积的形式表示出来:x = ...
- 反质数(Antiprimes)
转载http://www.cnblogs.com/tiankonguse/archive/2012/07/29/2613877.html 问题描述: 对于任何正整数x,起约数的个数记做g(x).例如g ...
- COJN 0486 800401反质数 呵呵呵呵呵
800401反质数 难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 将正整数 x 的约数个数表示为 g(x).例如,g(1)=1 ...
- bzoj:3085: 反质数加强版SAPGAP
Description 先解释一下SAPGAP=Super AntiPrime, Greatest AntiPrime(真不是网络流),于是你就应该知道本题是一个关于反质数(Antiprime)的问题 ...
随机推荐
- linux upstart启动配置
程序名.conf放在/etcc/init/目录下# 注释 description "your-server" author "xxx" start on run ...
- Postman怎么用?
国庆期间的工作就是搞清楚postman怎么用?
- C# 语言规范_版本5.0 (第17章 特性)
1. 特性 C# 语言的一个重要特征是使程序员能够为程序中定义的实体指定声明性信息.例如,类中方法的可访问性是通过使用 method-modifiers(public.protected.intern ...
- Redis--Latest Windows Version
Redis Windows Ver https://github.com/MSOpenTech/redis/releases service-install.batredis-server.exe - ...
- aop代理方式引起的spring注入bean(实现类)与获取bean(实现类)出错
描述: 现象一 :A 为 接口,AImpl 为 A 的实现类,且 AImpl 受 aop 扫描,且 aop 无特殊配置 此时若:Spring 中 注入 AImpl 类型的bean,获取一样 ...
- Learning from the CakePHP source code - Part I
最近开始痛定思痛,研究cakephp的源码. 成长的路上从来没有捷径,没有小聪明. 只有傻傻的努力,你才能听到到成长的声音. 下面这篇文章虽然过时了,但是还是可以看到作者的精神,仿佛与作者隔着时空的交 ...
- 3.Thread中的静态方法
1.currentThread() public class Thread14 extends Thread{ static { System.out.println("静态块的打印:&qu ...
- js 对象类型 (对象的属性 ,对象的方法) this 关键字
$(function () { var observation = { init: function () { this.render();//断点:this bind :function() che ...
- Entitlements (授权机制) 延伸
授权机制 (Entitlements) 到目前为止,我们都假设所有的证书起到的作用都是一样的,并且假设如果我们有了一个有效的证书代码签名也就相应的有效.然而这当然不是唯一的规则.操作系统有许多标准来检 ...
- Hibernate5-课程笔记2
单表的增删改查操作: (1)定义获取Session和SessionFactory的工具类: package com.tongji.utils; import org.hibernate.Session ...