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. Python学习笔记(四十五)网络编程(1)TCP编程

    摘抄:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014320043745 ...

  2. 【洛谷P2676】超级书架

    题目描述 Farmer John最近为奶牛们的图书馆添置了一个巨大的书架,尽管它是如此的大,但它还是几乎瞬间就被各种各样的书塞满了.现在,只有书架的顶上还留有一点空间. 所有N(1 <= N & ...

  3. python初步学习-面向对象之 类(二)

    方法重写 如果你的父类方法的功能不能满足你的需求,你可以在子类重写你父类的方法: #!/usr/bin/env python #coding:utf8 class Parent: def myMeth ...

  4. win8扁平风格的物流公司网站后台管理模板——后台

    链接:http://pan.baidu.com/s/1o79Zp2M 密码:tqrz

  5. 生成验证码tp

    js里拼接随机数 页面上链接 去掉后缀名

  6. java反序列化漏洞

    http://www.freebuf.com/vuls/86566.html 有时间了  仔细阅读

  7. Deep Learning基础--SVD奇异值分解

    矩阵奇异值的物理意义是什么?如何更好地理解奇异值分解?下面我们用图片的例子来扼要分析. 矩阵的奇异值是一个数学意义上的概念,一般是由奇异值分解(Singular Value Decomposition ...

  8. ACM ICPC Kharagpur Regional 2017

    ACM ICPC Kharagpur Regional 2017 A - Science Fair 题目描述:给定一个有\(n\)个点,\(m\)条无向边的图,其中某两个点记为\(S, T\),另外标 ...

  9. nginx配置--event模块

    在nginx的配置中,event模块可以进行以下配置: 设置网络连接的序列化. 在Nginx服务器的多进程下,有可能出现惊群(Thundering herd problem)问题,指的是当某一个时刻只 ...

  10. acm专题---拓扑排序+优先队列

    struct node{ int id; int cnt; node(int _id,int _cnt):id(_id),cnt(_cnt){} bool operator<(node a) c ...