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. php的swoole扩展中onclose和onconnect接口不被调用的问题

    在用swoole扩展写在线聊天例子的时候遇到一个问题,查了不少资料,现在记录于此. 通过看swoole_server的接口文档,回调注册接口on中倒是有明确的注释: * swoole_server-& ...

  2. 强大的网络通信框架(实现缓存)--第三方开源--volley

    Android Volley是Android平台上很好用的第三方开源网络通信框架.使用简答,功能强大. Android Volley的库jar包Volley.ja下载连接地址:Volley下载 下载后 ...

  3. android开源代码

    Android开源项目--分类汇总 转自:https://github.com/Trinea/android-open-project Android开源项目第一篇——个性化控件(View)篇 包括L ...

  4. 倒水问题 (codevs 1226) 题解

    [问题描述] 有两个无刻度标志的水壶,分别可装x升和y升 ( x,y 为整数且均不大于100)的水.设另有一水缸,可用来向水壶灌水或接从水壶中倒出的水, 两水壶间,水也可以相互倾倒.已知x升壶为空壶, ...

  5. C# 修改IE 源代码参照样例

    using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; ...

  6. Python多版本安装 Python2.7和Python3.5

    声明:本文仅仅在win8.1测试通过! 1.下载 Python2.7,3.5 2.依次安装Python27(c:\Python27)  Python35(c:\Python35) 3.c:\Pytho ...

  7. C语言--通用类型栈

    #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <string.h&g ...

  8. EXCLE中快速插入图片

    在excle中怎么快速插入图片呢,一张一张点实在比较麻烦 解决办法: <table><img src="D:\A.png" width="60" ...

  9. [Letcode] 1. Two Sum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  10. Android--发送短信,并且通知发送方

    1.发送短信涉及到权限,我们需要把权限加上 2.当我们发送短信时,不管发送是否成功,接收方是否接收到,系统都会发送广播 3.这时我们注册广播去接收一下就可以了 4.布局文件很简单,里面就两个EditT ...