题意:

一个数的质因子如果只是2,3,5,7中的若干个。则这个数叫做humble number。

例如:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ...

给n,问第n个humble number是多少。

思路:

所有的humble数的构造都是:(2^a)*(3^b)*(5^c)*(7^d)。a,b,c,d大于等于0。

X=a+b+c+d代表这个数是第X个humble数。

假设前i-1个humble数已经求出来了,第i个humble数如何求呢?

一定是前i-1个humble数中的某个humble数乘以2或乘以3或乘以5或乘以7得到的。

好了,枚举前i-1个humble数,找出大于第i-1个humble数并且是最小,那么它就是第i个humble数了。

看代码

代码:

ll a[5850];
int cn=0; int main(){ a[1]=1;
cn=1; while(cn<5842){
ll ans=INF;
ll temp;
rep(i,1,cn){
temp=a[i]*2; if(temp>a[cn]) ans=min(ans,temp);
temp=a[i]*3; if(temp>a[cn]) ans=min(ans,temp);
temp=a[i]*5; if(temp>a[cn]) ans=min(ans,temp);
temp=a[i]*7; if(temp>a[cn]) ans=min(ans,temp);
}
a[++cn]=ans;
} int n;
while(scanf("%d",&n),n){
int t=n%10;
if(t==1 && n%100!=11){
printf("The %dst humble number is ",n);
}
else if(t==2 && n%100!=12){
printf("The %dnd humble number is ",n);
}
else if(t==3 && n%100!=13){
printf("The %drd humble number is ",n);
}
else{
printf("The %dth humble number is ",n);
}
printf("%I64d.\n",a[n]);
} return 0;
}

hdu 1058 Humble Numbers(构造?枚举?)的更多相关文章

  1. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  2. HDU 1058 Humble Numbers (DP)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  3. hdu 1058:Humble Numbers(动态规划 DP)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  4. HDU 1058 Humble Numbers (动规+寻找丑数问题)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  5. HDU 1058 Humble Numbers(离线打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...

  6. hdu 1058 Humble Numbers

    这题应该是用dp来做的吧,但一时不想思考了,写了个很暴力的,类似模拟打表,然后排序即可,要注意的是输出的格式,在这里wa了一发,看了别人的代码才知道哪些情况没考虑到. #include<cstd ...

  7. HDU 1058 Humble Numbers【DP】

    题意:给出丑数的定义,只含有2,3,5,7这四个素数因子的数称为素数.求第n个丑数. 可以先观察几个丑数得出规律 1:dp[1] 2:min(1*2,1*3,1*5,1*7) 3:min(2*2,1* ...

  8. SOJ1029 Humble Numbers (枚举)

    A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...

  9. HDU 1058 Humble Number

    Humble Number Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humbl ...

随机推荐

  1. 论文解读(BYOL)《Bootstrap Your Own Latent A New Approach to Self-Supervised Learning》

    论文标题:Bootstrap Your Own Latent A New Approach to Self-Supervised Learning 论文方向:图像领域 论文来源:NIPS2020 论文 ...

  2. 【OI】计算分子量 Molar mass UVa 1586 题解

    题目:(由于UVa注册不了,还是用vjudge) https://vjudge.net/problem/UVA-1586 详细说明放在了注释里面.原创. 破题点在于对于一个元素的组合(元素+个数),只 ...

  3. nginx环境下提交表单一直301

    之前网站一直正常的,现在提交表单一直301 原因: 前几天把网站http升为https协议,需要去掉连接 // 前内容 把 <form method ="post" acti ...

  4. prometheus、node_exporter设置开机自启动

    方法一.写入rc.local 在/etc/rc.local文件中编辑需要执行的脚本或者命令,我个人习惯用这个,因人而异,有的项目可能需要热加载配置文件,用服务会更好 #普罗米修斯启动,需要后面接con ...

  5. Postman 如何调试加密接口?

    大家好,我是安果! 众所周知,Postman 是一款非常流行且易用的 API 调试工具,在接口调试或测试时经常被使用针对普通 API 接口,我们可以直接在 Postman 中输入 URL.Query ...

  6. lua常用一些功能

    lua在openresty中获取请求的请求头 local head_table = ngx.req.get_headers() 由于table类型,无法直接使用ngx.say()显示,需要转换为cjs ...

  7. JS获取contextPath的方法

    function getContextPath() { var pathName = document.location.pathname;    var index = pathName.subst ...

  8. 《手把手教你》系列技巧篇(二十八)-java+ selenium自动化测试-处理模态对话框弹窗(详解教程)

    1.简介 在前边的文章中窗口句柄切换宏哥介绍了switchTo方法,这篇继续介绍switchTo中关于处理alert弹窗的问题.很多时候,我们进入一个网站,就会弹窗一个alert框,有些我们直接关闭, ...

  9. MR 01 - MapReduce 计算框架入门

    目录 1 - 什么是 MapReduce 2 - MapReduce 的设计思想 2.1 如何海量数据:分而治之 2.2 方便开发使用:隐藏系统层细节 2.3 构建抽象模型:Map 和 Reduce ...

  10. 在开源项目或项目中使用git建立fork仓库

    前言: vector我们经常使用,对vector里面的基本函数构造函数.增加函数.删除函数.遍历函数我们也会用到.其中在使用遍历之后erase删除元素过程中,会出现一种删除最后一个元素破坏了迭代器的情 ...