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. 使用dict和set

    Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. d = {'Michael': 95, ...

  2. abiword Related Pages

    Application Framework The 'af' directory contains all source code for the cross-platform application ...

  3. linux mysql 优化

    第一 在 /etc/my.cnf 中加入 skip-name-resolve ,重启mysql,这样就能禁用DNS解析,连接速度会快很多.不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用 ...

  4. centos 6.5 安装 nginx+php+mysql

    一.准备工作 (1)配置防火墙 1.首先检查iptables服务的状态 [root@woxplife ~]# service iptables status iptables: Firewall is ...

  5. Weblogic缓存

    缓存:如果脱离IDE工具的话,weblogic的文件会在\user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_user文件夹中 ...

  6. jQuery 序列化表单数据 serialize() serializeArray()

    1.serialize()方法 格式:var data = $("form").serialize(); 功能:将表单内容序列化成一个字符串. 这样在ajax提交表单数据时,就不用 ...

  7. 【Xamarin挖墙脚系列:Xamarin的终极破解步骤(更新)】

    前面文章中,我们可以找到对应版本的补丁. Xamarin的 4.0.1717 版本,在补丁的地址中,有作者整理的全部的安装包.迅雷磁力贴: magnet:?xt=urn:btih:9FD298AA61 ...

  8. 2015第10周四-CSS小结

    这两天做前台页面发现个人在CSS前端方法很多基础知识都忘了,晚上又搜索学习了下,把相关内容摘录总结. CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. selector {declara ...

  9. CXF之webservice

    使用 CXF 做 webservice 简单例子     Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构.它允许创建高性能和可扩展的服务,您可以将这 ...

  10. poj 1020 Anniversary Cake(切正方形蛋糕+搜索)

                                                                                                         ...