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<cstdio>
#include<string.h>
using namespace std;
const int MAXN=;
int num2=,num3=,num5=,num7=;
long long s[MAXN];
void Sort()//sort函数是用来求humble number数组的
{
s[]=;
s[num2]=,s[num3]=,s[num5]=;
long long min=s[num2]*;
int num2=,num3=,num5=,num7=;
for(int i=;i<;i++)
{ min=s[num2]*;
if(min>s[num3]*)
min=s[num3]*;
if(min>s[num5]*)
min=s[num5]*;
if(min>s[num7]*)
min=s[num7]*;
s[i]=min;
// printf("%d ",s[i]);
//printf("%d ",min);
if(min==s[num2]*)
num2++;
if(min==s[num3]*)
num3++;
if(min==s[num5]*)
num5++;
if(min==s[num7]*)
num7++;
}
}
int main()
{
int n;
Sort();
while(scanf("%d",&n)!=EOF&&n)
{
if(n%==&&n%!=&&n!=)//当时卡在n%100!=11和12,13这里了,wa了几次!
printf("The %dst humble number is ",n);
else if(n%==&&n%!=&&n!=)
printf("The %dnd humble number is ",n);
else if(n%==&&n%!=&&n!=)
printf("The %drd humble number is ",n);
else printf("The %dth humble number is ",n);
printf("%lld.\n",s[n-]);
}
return ;
}

A - Humble Numbers的更多相关文章

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

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

  3. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  4. Humble Numbers

    Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9988 Accepted: 4665 Descri ...

  5. 洛谷P2723 丑数 Humble Numbers

    P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...

  6. HDU 1058 Humble Numbers (DP)

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

  7. HDOJ 1058 Humble Numbers(打表过)

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

  8. The number of divisors(约数) about Humble Numbers

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  9. HDU1058 Humble Numbers 【数论】

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

随机推荐

  1. 【Python】我的Python学习笔记【1】【using Python 2】

    1.模块格式 #!/usr/bin/env python # -*- coding: utf-8 -*- ... ...def main(): ...... ... if __name__=='__m ...

  2. spring cache

    spring-ehcache.xml文件内容如下: <?xml version="1.0" encoding="UTF-8"?> <beans ...

  3. 【Spring】Junit加载Spring容器作单元测试

    如果我们需要对我们的Service方法作单元测试,恰好又是用Spring作为IOC容器的,我们可以这么配置Junit加载Spring容器,方便做单元测试. > 基本的搭建 (1)引入所需的包 & ...

  4. C#中静态与非静态方法比较

    C#静态方法与非静态方法的区别不仅仅是概念上的,那么他们有什么具体的区别呢?让我们通过本文向你做一下解析. C#的类中可以包含两种方法:C#静态方法与非静态方法.那么他们的定义有什么不同呢?他们在使用 ...

  5. [Oracle] SQL*Loader 详细使用教程(4)- 字段列表

    在上一篇中我们介绍了SQL*Loader中最重要的文件——控制文件,而本篇要介绍控制文件中最重要的部分——字段列表,字段列表的作用是把数据文件中的记录和数据库中表的列对应起来,下面是字段列表的一个例子 ...

  6. Android Studio教程从入门到精通

    最新2.0系列文章参考: Android Studio2.0 教程从入门到精通Windows版 - 安装篇Android Studio2.0 教程从入门到精通Windows版 - 入门篇Android ...

  7. 【bzoj1798】维护序列

    线段树维护两个标记. *0的操作在实质上没有任何影响. #include <cstdio> #include <cctype> #define rep(i,a,b) for ( ...

  8. WIN7 java7 环境变量配置

    1 首先要搞清楚,java可能安装了两个部分,一个叫JDK,一个叫jre.其中jre若已经安装了,那么在安装JDK的时候,就不要放在默认的C:\Program File\java\XXX目录.最好另起 ...

  9. DEV GridControl TableView隔行换色/奇偶行换色

    GridControl中的TableView“奇偶行换色”这件事情纠结了我好几天,虽然已经是上个月的事情,好歹记录一下吧,万一有谁要用到呢. GridControl是长这个样子的, <dxg:G ...

  10. js6类和对象

    // 第一种:对象 var person = {};// 或者var obj = new Object(); person.name = "king"; person.age =  ...