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. 获取Spring的ApplicationContext的几种方式

    Application Context定义 简单来说就是Spring中的高级容器,可以获取容器中的各种bean组件,注册监听事件,加载资源文件等功能. 具体定义可以参考官网:https://sprin ...

  2. Razor使用Parse()时最好指定“缓存名”

    为什么? 本文的标题,明显有一种提醒的口吻. 从18年的生活经验看,如果想提醒人要怎么办,不要怎么办. 最好说明原因.那么小编开始说明原因喽. 哦对,说原因之前,先说交代一下背景,一句话 在非mvc下 ...

  3. 从docker到docker-compose部署一个nginx+flask+mysql+redis应用

    目的是把一个flask项目的mysql数据库.redis数据库.flask应用.nginx服务分别装到四个容器中,然后用docker-compose命令同时启动与关闭 一.安装docker Docke ...

  4. 使用ctypes在Python中调用C++动态库

    使用ctypes在Python中调用C++动态库 入门操作 使用ctypes库可以直接调用C语言编写的动态库,而如果是调用C++编写的动态库,需要使用extern关键字对动态库的函数进行声明: #in ...

  5. 【转载】selenium之 定位以及切换frame(iframe)

    更多关于python selenium的文章,请关注我的专栏:Python Selenium自动化测试详解 总有人看不明白,以防万一,先在开头大写加粗说明一下: frameset不用切,frame需层 ...

  6. juey点击tr选中里面的radio

    //点击一行选中银行卡 $("tr").bind("click",function(){ $("input:radio").attr(&qu ...

  7. css 水平、垂直居中

    水平居中 行内元素 行内元素:(img.span.文字等行内元素),通过在父级元素设置 text-align:center 使元素水平居中. 块级元素 块级元素:(div.p.h1...h6.ul.l ...

  8. linux下使用privoxy将socks转为http代理

    此博客不在更新,我的博客新地址:www.liuquanhao.com ----------------------------------------------------------------- ...

  9. Linux /etc/cron.d作用(转自 定时任务crontab cron.d)

    原文链接:http://huangfuligang.blog.51cto.com/9181639/1608549 一.cron.d增加定时任务 当我们要增加全局性的计划任务时,一种方式是直接修改/et ...

  10. 学习笔记(二) 瓜娃(guava)的API快速熟悉使用

    1,大纲 让我们来熟悉瓜娃,并体验下它的一些API,分成如下几个部分: Introduction Guava Collection API Guava Basic Utilities IO API C ...