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<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
#include<deque>
using namespace std;
typedef long long LL;
const int maxn = 1e4+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
//#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1
typedef long long ll;
#define N 100010 int dp[]; void init(){
dp[]=;
int p2,p3,p5,p7;
p2=p3=p5=p7=;
int cnt=;
while(cnt<=){
dp[cnt]=min(dp[p2]*,min(dp[p3]*,min(dp[p5]*,dp[p7]*)));
if(dp[cnt]==*dp[p2]) p2++;
if(dp[cnt]==*dp[p3]) p3++;
if(dp[cnt]==*dp[p5]) p5++;
if(dp[cnt]==*dp[p7]) p7++;
cnt++; }
}
int main(){
init();
int n;
while(scanf("%d",&n)&&n){
if(n%==&&n%!=) printf("The %dst humble number is %d.\n",n,dp[n]);
else if(n%==&&n%!=) printf("The %dnd humble number is %d.\n",n,dp[n]);
else if(n%==&&n%!=) printf("The %drd humble number is %d.\n",n,dp[n]);
else printf("The %dth humble number is %d.\n",n,dp[n]);
} return ;
}
												

POJ 2247 Humble Numbers的更多相关文章

  1. Poj 2247 Humble Numbers(求只能被2,3,5, 7 整除的数)

    一.题目大意 本题要求写出前5482个仅能被2,3,5, 7 整除的数. 二.题解 这道题从本质上和Poj 1338 Ugly Numbers(数学推导)是一样的原理,只需要在原来的基础上加上7的运算 ...

  2. 递推(三):POJ中的三道递推例题POJ 1664、POJ 2247和POJ 1338

    [例9]放苹果(POJ 1664) Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. In ...

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

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

  5. A - Humble Numbers

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

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

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

  7. Humble Numbers

    Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9988 Accepted: 4665 Descri ...

  8. 洛谷P2723 丑数 Humble Numbers

    P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...

  9. HDU 1058 Humble Numbers (DP)

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

随机推荐

  1. Linux运维工程师必须掌握的基础技能有哪些?

    这个问题挺好的,回答这个问题也是对自身的审查,看看自己还欠缺哪些.(所以我估计得好好思考下,也许下一刻我就会突然惊醒,发现我还是战⑤渣) 首先限定在Linux运维工程师上 回答仅代表我想到,不代表我都 ...

  2. Mysql索引结构及常见索引的区别

    一.Mysql索引主要有两种结构:B+Tree索引和Hash索引 Hash索引 mysql中,只有Memory(Memory表只存在内存中,断电会消失,适用于临时表)存储引擎显示支持Hash索引,是M ...

  3. C# PictureBox控件畫圖

    PictureBox的正方向: BitMap初始化: Bitmap bt = new Bitmap(Width,Height);      Graphics gdi = Graphics.FromIm ...

  4. hashCode和equal

    转自:https://www.cnblogs.com/dolphin0520/p/3681042.html hashCode方法在Object类中: public native int hashCod ...

  5. bzoj 2120 数颜色 (带修莫队)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2120 题意:两种操作:Q 询问区间  l - r  内颜色的种类 ,R 单点修改 思路 ...

  6. 【AtCoder010】A - Addition(奇偶)

    AtCoder Grand Contest 010 A题 题目链接 题意 n个数,每次取两个奇偶性相同的数用他们的和代替他们,问最后能否只剩下一个数. 题解 因为奇偶相同的两个数之和一定是偶数,所以Y ...

  7. 自学Linux Shell11.5-执行数字运算

    点击返回 自学Linux命令行与Shell脚本之路 11.5-执行数字运算 1. Shell基本运算符 Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符 ...

  8. 打开SharePoint 2013 web application显示iis 欢迎页面

    当我打开SP web application时,页面显示如下: 查看event log,发现有一些8315-8317之类的error,发现把request management service停掉后, ...

  9. json序列化 & 反序列化

    json序列化: json的dumps方法可以将json格式数据序列为python的相关数据类型,比如str,常用于打印,另外,在序列化时,中文汉字被转换为unicode编码,在dumps函数中添加参 ...

  10. 洛谷P4043 支线剧情

    题意:给定DAG,通过每条边需要时间. 从某号点回到1号点不需要时间. 从1号点出发,求最少要多久才能走完所有边. 解: 有源汇有上下界最小费用可行流. 直接连边,费用为时间,下界为1,无上界. 每个 ...