Problem Description
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.

Write
a program to find and print the nth element in this sequence

 
Input
The input consists of one or more test cases. Each test
case consists of one integer n with 1 <= n <= 5842. Input is terminated by
a value of zero (0) for n.
 
Output
For each test case, print one line saying "The nth
humble number is number.". Depending on the value of n, the correct suffix "st",
"nd", "rd", or "th" for the ordinal number nth has to be used like it is shown
in the sample output.
 
Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
 
Sample Output
The 1st humble number is 1.
The 2nd humble number is 2.
The 3rd humble number is 3.
The 4th humble number is 4.
The 11th humble number is 12.
The 12th humble number is 14.
The 13th humble number is 15.
The 21st humble number is 28.
The 22nd humble number is 30.
The 23rd humble number is 32.
The 100th humble number is 450.
The 1000th humble number is 385875.
The 5842nd humble number is 2000000000.
 /*看题解AC的,结果开始开编译错误了几次,oj说是min()没定义,那为什么自己编译会通过,然后自己写了min(),dp方程 dp[i]=f[i]=min(f[a]*2,min(f[b]*3,min(f[c]*5,f[d]*7)))*/
#include<stdio.h>/*dev编译后运行程序中途闪退,提交后却对的*/
using namespace std;
int min(int a,int b)
{
return a>b?b:a;
}
int humble[];
void factor()/*马丹看了半天也是似懂非懂,比赛时完全想不出来这么求*/
{
int post1=,post2=,post3=,post4=,na,nb,nc,nd,i;
humble[]=;
for(i=;i<=;i++)
{
humble[i]=min(na=humble[post1]*,min(nb=humble[post2]*,min(nc=humble[post3]*,nd=humble[post4]*)));
if(humble[i]==na) post1++;
if(humble[i]==nb) post2++;
if(humble[i]==nc) post3++;
if(humble[i]==nd) post4++;
}
}
int main()
{
int n;
factor();
while(~scanf("%d",&n))
{
if(n==)
break;
printf("The %d",n);
if(n%!=&&n%==)
printf("st");
else if(n%!=&&n%==)
printf("nd");
else if(n%!=&&n%==)
printf("rd");
else
printf("th");
printf(" humble number is %d.\n",humble[n]);
}
}

humble number(hd1058)的更多相关文章

  1. HDU 1058 Humble Number

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

  2. HDU Problem D [ Humble number ]——基础DP丑数序列

    Problem D Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  3. HDU - The number of divisors(约数) about Humble Numbers

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

  4. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  5. The number of divisors(约数) about Humble Numbers

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  6. HDU1492/The number of divisors(约数) about Humble Numbers

    题目连接 The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory L ...

  7. HDUOJ---The number of divisors(约数) about Humble Numbers

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  8. HDU-1492-The number of divisors(约数) about 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. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

随机推荐

  1. php在cli和cgi方式下获取服务器ip的实例

    php cli方式下获取服务器ip php内核没有提供这样的命令,需要借助linux中的命令ifconfig来实现,如下两个函数代码: function getServerIp(){          ...

  2. arcpy批量打印地图

    有个处理数据的需求是把一个图层中的要素单独显示在底图上,设置固定的比例尺,并打印出图片. 考虑到后续会有重复的大量的数据要处理,决定使用arcpy处理. 首先新建一个mxd底图文档,把需要打印的地图都 ...

  3. UPX和WinUpack压缩壳的使用和脱法 - 脱壳篇06

    UPX和WinUpack压缩壳的使用和脱法 - 脱壳篇06 让编程改变世界 Change the world by program 今天小甲鱼给大家介绍两款压缩壳:UPX和WinUpack. UPX是 ...

  4. 对$NOMOD51的理解

    很多朋友在看asm代码的时候,对下面的语句不是很了解,下面解说一下. $NOMOD51 $INCLUDE (REG932.INC) 解释:$NOMOD51,这一指令功能是使A51不识别8051的所有预 ...

  5. HttpApplication实战大文件上传 (第四篇)

    一.Asp.net中的文件上传 在Asp.net 1.1中,文件在上传过程中将被全部保存在内存中,对于大文件来说,会造成内存空间的过度使用,可能会招致恶意攻击.为了解决这个问题,Asp.net在配置文 ...

  6. 软件架构 "4+1" 视图模型

    1995年,Philippe Kruchten在<IEEE Software>上发表了题为<The 4+1 View Model of Architecture>的论文,引起了 ...

  7. selenium webdriver使用过程中出现Element is not currently visible and so may not be interacted with的处理方法

    参考文章: http://blog.csdn.net/passionboyxie/article/details/28661107 http://www.spasvo.com/ceshi/open/k ...

  8. magento添加系统sections配置时应注意的事项

    (1)只有在新增sections是需要增加对应的acl配置,这个配置可以放在config.xml中或者放在adminhtml.xml中 <adminhtml> <acl> &l ...

  9. Unity 读取Excel

    游戏有大多数配置文件,比如玩家等级,游戏商店信息等等.通常情况下把这些放入excel中来读取 第一种解决方案: xlsx –> csv –> 改变成UTF-8 或者Unicode编码 –& ...

  10. android面试题集1

    Android 面试题(有详细答案) 附带答案,共100分 一.选择题(30题,每题1.5分,共45分) 1.java.io包中定义了多个流类型来实现输入和输出功能,可以从不同的角度对其进行分类,按功 ...