Humble Numbers

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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.
#include <iostream>
#include <stdio.h>
using namespace std;
int f[5843],n;
int i,j,k,l; int min(int a,int b,int c,int d)
{
int min=a;
if(b<min) min=b;
if(c<min) min=c;
if(d<min) min=d; if(a==min) i++;
if(b==min) j++;
if(c==min) k++;
if(d==min) l++; return min;//a或b或c或d
} int main()
{
i=j=k=l=1;
f[1]=1;
for(int t=2; t<=5842; t++)
{
f[t]=min(2*f[i],3*f[j],5*f[k],7*f[l]);
}
while(scanf("%d",&n)&&n!=0)
{
if(n%10==1&&n%100!=11)
printf("The %dst humble number is %d.\n",n,f[n]);
else if(n%10==2&&n%100!=12)
printf("The %dnd humble number is %d.\n",n,f[n]);
else if(n%10==3&&n%100!=13)
printf("The %drd humble number is %d.\n",n,f[n]);
else
printf("The %dth humble number is %d.\n",n,f[n]);
}
return 1;
} //#include<stdio.h>
//#define min(a,b) (a<b?a:b)
//#define min4(a,b,c,d) min(min(a,b),min(c,d))
//int a[5850];//存放丑数
//
//int main()
//{
// int n=1;
// int p2,p3,p5,p7;
// p2=p3=p5=p7=1;//2,3,5,7的计数器
// a[1]=1;
// while(a[n]<2000000000)//从2开始递推计算,一共5842个丑数
// {
// a[++n] = min4(2*a[p2],3*a[p3],5*a[p5],7*a[p7]);//取最小值,相应的计数器加1
// if(a[n]==2*a[p2]) p2++;
// if(a[n]==3*a[p3]) p3++;
// if(a[n]==5*a[p5]) p5++;
// if(a[n]==7*a[p7]) p7++;
// }
// while(scanf("%d",&n) && n)
// {
// if(n%10 == 1&&n%100!=11)
// printf("The %dst humble number is ",n);
// else if(n%10 == 2&&n%100!=12)
// printf("The %dnd humble number is ",n);
// else if(n%10 == 3&&n%100!=13)
// printf("The %drd humble number is ",n);
// else
// printf("The %dth humble number is ",n);
// printf("%d.\n",a[n]);
// }
// return 0;
//
//}

hdu 1058 dp.Humble Numbers的更多相关文章

  1. ACM -- 算法小结(九)DP之Humble numbers

         DP -- Humble numbers  //一开始理解错题意了,题意是是说一些只有唯一一个质因数(质因数只包括2,3,5,7)组成的数组,请找出第n个数是多少 //无疑,先打表,否则果断 ...

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

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

  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(动态规划 DP)

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

  5. Humble Numbers HDU - 1058

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

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

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

  7. [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 ...

  8. HDU 1058 Humble Number

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

  9. DP 60题 -3 HDU1058 Humble Numbers DP求状态数的老祖宗题目

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

随机推荐

  1. Discrete Logging(POJ2417 + BSGS)

    题目链接:http://poj.org/problem?id=2417 题目: 题意: 求一个最小的x满足a^x==b(mod p),p为质数. 思路: BSGS板子题,推荐一篇好的BSGS和扩展BS ...

  2. 旅游(CSUST省赛选拔赛2+状压dp+最短路)

    题目链接:http://csustacm.com:4803/problem/1016 题目: 思路:状压dp+最短路,比赛的时候有想到状压dp,但是最短路部分写挫了,然后就卡死了,对不起出题人~dis ...

  3. 2017ACM暑期多校联合训练 - Team 1 1006 HDU 6038 Function (排列组合)

    题目链接 Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m ...

  4. VC孙鑫老师第八课:你能捉到我吗?

    第一步,首先在对话框窗口上放上两个一模一样的按钮控件 第二步,由于是按钮响应鼠标移动上去的事件,因此需要重新派生按钮类: 第三步,在窗口类中声明并使用自定义按钮对象(记得在窗口类中包含自定义按钮类的头 ...

  5. 背包DP FOJ 2214

    题目:http://acm.fzu.edu.cn/problem.php?pid=2214 (http://www.fjutacm.com/Problem.jsp?pid=2053) 这题看起来是一题 ...

  6. 关于linux系统如何实现fork的研究(二)【转】

    转自:http://www.aichengxu.com/linux/7166015.htm 本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 引言 前一篇关于li ...

  7. USB 3.0传输规格

    通用序列总线(USB) 从1996问世以来,一统个人电脑外部连接界面,且延伸至各式消费性产品,早已成为现代人生活的一部分.2000年发表的USB 2.0 High-speed规格,提供了480Mbps ...

  8. MySQL Warning: Using a password on the command line interface can be insecure.解决办法

    转自 http://www.cnblogs.com/sunss/p/6256706.html  被一个小朋友问到,直接公布答案: If your MySQL client/server version ...

  9. mui app页面刷新问题 plus.webview.getWebviewById("").reload()

    /** * 放回指定页面,并且刷新指定页面 * @param {Object} pageId 指定页面ID */ mui.app_refresh=function(pageId){ if(!mui.i ...

  10. MYSQL三种安装方式--二进制包安装

    1. 把二进制包下载到/usr/local/src下 2. 如果是tar.gz包,则使用tar zxvf 进行解压 如果是tar包,则可以使用tar xvf 进行解压 3. $ mv mysql-5. ...