Humble Number

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.

题目大意:求出以2,3,5,7为因子的第n个数字。

代码如下:注意111后面跟th

 # include<iostream>
# include<cstdio>
# include<cstring>
# include<cstdlib>
# define LL __int64 using namespace std; int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
}
LL dp[],num;
void init()
{
num = ;
LL i,j,k,m;
for(i=; i<=; i*=)
{
for(j=; i*j<=; j*=)
{
for(k=; i*j*k<=; k*=)
{
for(m=; i*j*k*m<=; m*=)
{
dp[num] = i*j*k*m;
//printf("dp[%I64d] = %I64d\n",num,dp[num]);num定义成了__int64位,之前一直输出%d,看结果一直不对,坑
num++;
}
}
}
}
qsort(dp,num,sizeof(dp[]),cmp);
}
int main()
{
init();
int n,i,j,a,b,c;
while(scanf("%d",&n)&&n)
{
if(n%== &&n% != )
printf("The %dst humble number is ",n);
else if(n%== &&n% != )
printf("The %dnd humble number is ",n);
else if(n%== &&n% != )
printf("The %drd humble number is ",n);
else
printf("The %dth humble number is ",n);
printf("%I64d.\n",dp[n-]);
}
return ;
}

HDU 1058 Humble Number的更多相关文章

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

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

  2. HDU 1058 Humble Numbers(离线打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...

  3. hdu 1058 Humble Numbers

    这题应该是用dp来做的吧,但一时不想思考了,写了个很暴力的,类似模拟打表,然后排序即可,要注意的是输出的格式,在这里wa了一发,看了别人的代码才知道哪些情况没考虑到. #include<cstd ...

  4. HDU 1058 Humble Numbers【DP】

    题意:给出丑数的定义,只含有2,3,5,7这四个素数因子的数称为素数.求第n个丑数. 可以先观察几个丑数得出规律 1:dp[1] 2:min(1*2,1*3,1*5,1*7) 3:min(2*2,1* ...

  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(动态规划 DP)

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

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

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

  8. hdu 1058 Humble Numbers(构造?枚举?)

    题意: 一个数的质因子如果只是2,3,5,7中的若干个.则这个数叫做humble number. 例如:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 1 ...

  9. hdu 1058 dp.Humble Numbers

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

随机推荐

  1. 一、FreeMarker 模版开发指南 第一章 入门

    所有资料来自 南磊 翻译的官方文档,我弄简单了,适合自己以后拿出来翻看. 章节内容如下: 简介 模板+数据模型=输出 数据模型一览 模板一览 一.模板  +  数据模型  =  输出 输出结果: &l ...

  2. 菜单设计器(Menu Designer)及其B/S,C/S双重实现(B/S开源)

    ERP/MIS开发 菜单设计器(Menu Designer)及其B/S,C/S双重实现(B/S开源)   一直从事ERP/MIS的开发工作,今天来展现一下菜单设计器的设计,及其用途,并对B/S部分代码 ...

  3. iOS开发-表视图的使用

    // // ViewController.m // Simple Table // // Created by Jierism on 16/7/20. // Copyright © 2016年 Jie ...

  4. android125 zhihuibeijing 缓存

    ## 三级缓存 ## - 内存缓存, 优先加载, 速度最快 - 本地缓存(内存卡), 次优先加载, 速度快 - 网络缓存, 不优先加载, 速度慢,浪费流量 package com.itheima.zh ...

  5. 列式存储 V.S. 行式存储

    列式数据库 http://zh.wikipedia.org/wiki/%E5%88%97%E5%BC%8F%E6%95%B0%E6%8D%AE%E5%BA%93 列式存储与行式存储 http://my ...

  6. java_Cookie_example(你上次访问的时间)

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...

  7. Java设计模式06:常用设计模式之适配器模式(结构型模式)

    1. Java之适配器模式(Adapter Pattern) (1)概述:    将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类,可以在一起 ...

  8. 有(无)符号char型及其溢出问题

    转载自:http://blog.sina.com.cn/s/blog_70ec9a6f01014j1h.html 1.char的有无符号类型 char 分为有符号性(signed)和无符号型(unsi ...

  9. quartz定时任务中常用的cron表达式

    一:定时cron的格式,一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素. 按顺序依次为: 1.秒(0~59) 2.分钟(0~59) 3.小时(0~23) 4.天(月(0~31,但是你需 ...

  10. eclipse引用头文件报错问题-解决方法

    最近在做一个U-BOOT相关的项目,经过几天的折腾最终放弃使用VIM和一堆附加插件.最终的出的结论是对于中大型工程项目还是要启用一些专业的IDE比较稳妥,尽管VIM提供的各种插件累加在一起足以实现专业 ...