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

InputThe 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. 
OutputFor 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. 丑数
 dp[i]=min(min(dp[a]*2,dp[d]*7),min(dp[b]*3,dp[c]*5));
if(dp[i]==dp[a]*2) a++;
if(dp[i]==dp[b]*3) b++;
if(dp[i]==dp[c]*5) c++;
if(dp[i]==dp[d]*7) d++;

输出的时候 注意13 12 11

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[];
int main()
{
dp[]=;
int a=,b=,c=,d=;
for(int i=;i<=;i++)
{
dp[i]=min(min(dp[a]*,dp[d]*),min(dp[b]*,dp[c]*));
if(dp[i]==dp[a]*) a++;
if(dp[i]==dp[b]*) b++;
if(dp[i]==dp[c]*) c++;
if(dp[i]==dp[d]*) d++; }
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 ;
}

Humble Numbers HDU - 1058的更多相关文章

  1. Humble Numbers HDU - 1058 2分dp

    JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two ...

  2. hdu 1058 dp.Humble Numbers

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

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

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

  4. HDU 1058 Humble Numbers (DP)

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

  5. hdu 1058:Humble Numbers(动态规划 DP)

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

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

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

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

  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. HDOJ 1058 Humble Numbers(打表过)

    Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...

随机推荐

  1. 搭建 FTP 文件服务

    1.安装并启动 FTP 服务 2.配置 FTP 权限 3.准备域名和证书 4.访问 FTP 安装 VSFTPD 使用 yum 安装 vsftpd: yum install vsftpd -y vsft ...

  2. 使用CSS渐变

    转载自:https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Using_CSS_gradients CSS 渐变 是在 CSS3 Image ...

  3. STL_string.vector中find到的iterator的序号

    ZC:注意,printf("0x%08X\n",vtr.end()); 打印出来 应该就是 0x00000000,∵ 它就是 指向最后一个元素的后面,应该是理解成 无意义      ...

  4. 远程Service的显示 / 隐式启动

    在进程间通信时,常会设计开启远程 Service 的情况.开启远程 Service 的方式有两种,一种时显示开启,一种是隐式开启.下面分别来看: 一.隐式开启 服务端:Service 所在 Andro ...

  5. 人脸识别demo使用教程

    最近在研究虹软家的arcface 人脸识别 demo,现在就给大家分享一下官方的demo**工程如何使用? **1.下载代码:git clone https://github.com/asdfqwra ...

  6. MySQL学习(十三)

    编码问题 乱码是如何形成的 1 解码时与实际编码不一致 可修复 2 传输过程中,编码不一致,导致字节丢失,不可修复,如把utf8转为GB2312 连接器的特性:连接客户端和服务器,客户端的字符先发给连 ...

  7. TEA加密/解密算法

    在游戏项目中,一般需要对资源或数据进行加密保护,最简单高效的加密算法就是采用位与或之类的,但是比较容易被人分析出来.TEA加密算法不但比较简单,而且有很强的抗差分分析能力,加密速度也比较快.可以根据项 ...

  8. Unity中角度与弧度之间的相互转换

    弧度数 = 角度数 * Mathf.Deg2Rad角度数 = 弧度数 * Mathf.Rad2Deg

  9. lua --- 点号 和 冒号

    冒号的作用:1.定义函数时,给函数添加隐藏的第一个参数 self2.调用函数时,默认把当前调用者作为第一个参数传递进去 如 a:b(c) 可以理解为 a.b(a, c) 以下是用点号的定义和调用函数的 ...

  10. (转)c# 断言类

    Assert 类 使用 true/false 命题验证单元测试中的条件. 继承层次结构 System.Object Microsoft.VisualStudio.TestTools.UnitTesti ...