Humble Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 17407    Accepted Submission(s): 7565
Problem 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 <stdio.h>
#define maxn 5845 int dp[maxn] = {1, 1};
int a, b, c, d;
const char *sam[] = { "st", "nd", "rd", "th" }; int min(int u, int v, int x, int y)
{
int tmp = u;
if(tmp > v) tmp = v;
if(tmp > x) tmp = x;
if(tmp > y) tmp = y; if(tmp == u) ++a;
if(tmp == v) ++b;
if(tmp == x) ++c;
if(tmp == y) ++d; return tmp;
} const char *f(int n)
{
if(n % 10 == 1 && n % 100 != 11) return sam[0];
if(n % 10 == 2 && n % 100 != 12) return sam[1];
if(n % 10 == 3 && n % 100 != 13) return sam[2];
return sam[3];
} int main()
{
int i, n;
a = b = c = d = 1;
for(i = 2; i < maxn; ++i)
dp[i] = min(dp[a] * 2, dp[b] * 3, dp[c] * 5, dp[d] * 7);
while(scanf("%d", &n), n)
printf("The %d%s humble number is %d.\n", n, f(n), dp[n]);
return 0;
}

HDU1058 Humble Numbers 【数论】的更多相关文章

  1. HDU1058 - Humble Numbers

    A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...

  2. DP 60题 -3 HDU1058 Humble Numbers DP求状态数的老祖宗题目

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

  3. Humble Numbers(hdu1058)

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

  4. 洛谷P2723 丑数 Humble Numbers [2017年 6月计划 数论07]

    P2723 丑数 Humble Numbers 题目背景 对于一给定的素数集合 S = {p1, p2, ..., pK},考虑一个正整数集合,该集合中任一元素的质因数全部属于S.这个正整数集合包括, ...

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

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

  7. A - Humble Numbers

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

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

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

  9. Humble Numbers

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

随机推荐

  1. Java中常见的几种类型转换

    public class Main { public static void main(String[] args){ //Int型数字转换成字符串 int num1=123456; //方法1 St ...

  2. C++ Input & Output

    1.C++ I/O各类之间的继承关系图 参考网址: http://www.cplusplus.com/reference/iolibrary/ Note: 在程序中包含iostream文件将自动创建8 ...

  3. shell学习之常用命令总结

    1.find命令 主要用途:主要用来做文件查找. 使用方法:查找文件的方式可以基于:文件名,文件时间属性,文件的所有者和组,文件权限属性,文件类型属性,文件大小,另外可以指定 查找目录的深度,排除指定 ...

  4. USB接口的SmartCard Class协议标准:ICCD and CCID

    ICCD是 Intergrated Circuit(s) card Device 的缩写.CCID是 Integrated Circuit(s) cards interface devices的缩写I ...

  5. poj 3053 Fence Repair(优先队列)

    题目链接:http://poj.org/problem?id=3253 思路分析:题目与哈夫曼编码原理相同,使用优先队列与贪心思想:读入数据在优先队列中,弹出两个数计算它们的和,再压入队列中: 代码如 ...

  6. layer 的常用属性

    layer的各种属性代码示例: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading ...

  7. Python基础 3----文件和网络

    1 Python文件IO 1 标转的输入和输出 print 方法:输出数据到标准的输出 raw_input 方法:标准的输入 2 file文件类 读文件 f = file(文件名, 模式) 有5种模式 ...

  8. 卸载了PL/SQL Developer,说一下与Toad for Oracle的对照

    曾经一直用PL/SQL Developer来管理Oracle.发现真的使用起来非常不方便.打开非常卡,并且界面左上角总是多出那个框,怎么都无法设置默认隐藏掉. 唯一让人认为非常值得的就是有一个美化工具 ...

  9. Android的AsyncTask类的解读

    国庆节放假.搞了半个月都没有上班了,coding的时候一点都不在状态,本来这篇文章是在国庆节前写完的,可是由于自己的懒 惰,导致延期到国庆节,哎,这种习惯真心不好呀...不多说了以下来进入正题 之前我 ...

  10. myeclipse8.5如何注册,转自他出

    Step: 1.建立一个任意名称的Java Project 2.在该工程中建立一个名文MyEclipseGen的Java文件(MyEclipseGen.java) 3.运行下面的代码,会在控制台出现& ...