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.
题意:输出能被2或3或5或7整除的第n个数,注意题目的11,12,13后面是th。。。
 #include<bits/stdc++.h>
using namespace std;
int main() {
int n,m2=,m3=,m5=,m7=,i,temp1,temp2;
int a[];
a[]=;
for(i=; i<=; i++) {
a[i]=min(min(*a[m2],*a[m3]),min(*a[m5],*a[m7]));
if(a[i]==*a[m2]) m2++;
if(a[i]==*a[m3]) m3++;
if(a[i]==*a[m5]) m5++;
if(a[i]==*a[m7]) m7++;
}
while(cin>>n,n) {
if(n%==&&n%!=)
printf("The %dst humble number is %d.\n",n,a[n]);
else if(n%==&&n%!=)
printf("The %dnd humble number is %d.\n",n,a[n]);
else if(n%==&&n%!=)
printf("The %drd humble number is %d.\n",n,a[n]);
else
printf("The %dth humble number is %d.\n",n,a[n]);
}
return ;
}

HDU1058Humble Numbers的更多相关文章

  1. hdu1058Humble Numbers(动态规划)

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

  2. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  3. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  4. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  5. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  6. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  7. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  8. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  9. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

随机推荐

  1. apache2反向代理node.js应用

    在之前记录的随笔中,只是介绍了怎么在apache2中使用proxy模块,后来查到了一些资料,可以通过下面网址查看配置块的详细参数信息 http://man.ddvip.com/soft/apache2 ...

  2. iOS中使用子线程的完整方法

    http://www.cnblogs.com/ygm900/archive/2013/06/23/3151691.html 第一步:开启子线程 //开启子线程到网络上获取数据 myFirstThrea ...

  3. Microsoft Visual C++ Runtime error解决方法

    1: 当出现下图时提示Microsoft Visual C++ Runtime error 2:此时不要关闭该对话框,然后打开任务管理器(Ctrl+Shift+Esc)如下图: 找到Microsoft ...

  4. DELPHI 单元文件结构

    unit Unit1; interface {接口部分开始} uses {引用单元列表,这是可选的,如果包含必须紧跟interface关键字} {接口部分声明常量/类型/变量/过程和函数,这些声明对引 ...

  5. SQL基础篇——如何搭建一个数据库

    特别提醒:所有的新建数据库,表,行,列都可以通过对象资源管理器操作,下面所讲的为查询操作方法 一.新建数据库 使用CREATE DATABASE语句建立数据库: 新建查询-- CREATE DATAB ...

  6. hdu 1429 胜利大逃亡(续)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...

  7. Android 上下文菜单实现

    1.覆盖Activity的onCreateContenxtMenu()方法,调用Menu的add方法添加菜单项(MenuItem). 2.覆盖Activity的onContextItemSelecte ...

  8. 1.Knockout.Js(简介)

    前言 最近一段时间在网上经常看到关于Knockout.js文章,于是自己就到官网看了下,不过是英文的,自己果断搞不来,借用google翻译了一下.然后刚刚发现在建立asp.net mvc4.0的应用程 ...

  9. 为什么要用Message Queue

    摘录自博客:http://dataunion.org/9307.html?utm_source=tuicool&utm_medium=referral 为什么要用Message Queue 解 ...

  10. 41.使用Chipscope时如何防止reg_wire型信号被优化掉

    随着FPGA设计复杂程度越来越高,芯片内部逻辑分析功能显得越来越重要.硬件层次上的逻辑分析仪价格十分昂贵,而且操作比较复杂.目前,FPGA芯片的两大供应商都为自己的FPGA芯片提供了软件层面上的逻辑分 ...