Humble Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14047    Accepted Submission(s): 6108

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.
 
 
 
带大一的不容易啊!(感慨一下。)这道题目就是刚刚看的时候没看懂什么意思,
o(︶︿︶)o 唉!硬伤啊!
下面我来详细解释一下吧。。。。。
 
Humble Numbers
    如果一个数的质因子只有2、3、5或7,那么这个数被称为Humble Numbers(差数)。
将正整数正序排列(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... )
你会发现前20个Humble Numbers(差数)。
现在,你的任务是编写一个程序将第n个Humble Numbers(差数)找出并打印出来。  
输入规范:
输入的数有许多组,其中的n均满足1 <= n <= 5842。如果输入0,则表示终止。
输出规范:
对于每一组数,分列几行输出“The nth humble number is number.”,其中nth必须根据英语词法规范写
为“1st、2nd、3rd、4th、5th、6th、7th、8th、9th、10th... ”。
 
 
 
详见代码:
#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))//一定要打括号。。。
int num[];
int main()
{
int n,p2,p3,p5,p7;
p2=p3=p5=p7=;
int m=;
num[]=;
while(m<=)
{
num[++m]=min(min(*num[p2],*num[p3]),min(*num[p5],*num[p7]));
if(num[m]==*num[p2])
p2++;
if(num[m]==*num[p3])
p3++;
if(num[m]==*num[p5])
p5++;
if(num[m]==*num[p7])
p7++;
}
while(scanf("%d",&n),n)
{
printf("The %d",n);
m=n/%;//十位不能为1,eg:11 12 13 111 112 113,,,
if(n%==&&m!=)
printf("st ");
else if(n%==&&m!=)
printf("nd ");
else if(n%==&&m!=)
printf("rd ");
else
printf("th ");
printf("humble number is %d.\n",num[n]);
}
return ;
}
 我想想这句num[++m]=min(min(2*num[p2],3*num[p3]),min(5*num[p5],7*num[p7]));其实,现在想想用快排也可以古,哈哈!    
 
        关键是题意!嗯嗯。
 
 

Humble Numbers(hdu1058)的更多相关文章

  1. SOJ1029 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. 【CF55D】Beautiful numbers(动态规划)

    [CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...

  3. hdu 1058:Humble Numbers(动态规划 DP)

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

  4. 【USACO 3.1】Humble Numbers(给定质因子组成的第n大的数)

    题意:给你k(≤100)个质数,求质因子只包含它们的第n大的数. 题解: 方法一:维护一个数组,一开始只有给出的质数在里面,用每个质数去乘以数组中每个数,然后归并排序,长度保留到n,一轮接一轮,直到乘 ...

  5. Round Numbers(组合数学)

    Round Numbers Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tota ...

  6. PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)

    1023 Have Fun with Numbers(20 分) Notice that the number 123456789 is a 9-digit number consisting exa ...

  7. Codeforces F. Vus the Cossack and Numbers(贪心)

    题目描述: D. Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. It is known that the ...

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

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

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

随机推荐

  1. ffplay源码分析5-图像格式转换

    本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10311376.html ffplay是FFmpeg工程自带的简单播放器,使用FFmpeg ...

  2. Distinct Substrings(spoj694)(sam(后缀自动机)||sa(后缀数组))

    Given a string, we need to find the total number of its distinct substrings. Input \(T-\) number of ...

  3. 设计模式《JAVA与模式》之访问者模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述访问者(Visitor)模式的: 访问者模式是对象的行为模式.访问者模式的目的是封装一些施加于某种数据结构元素之上的操作.一旦这些操作需要 ...

  4. 整理版jq 复习贴子

    1绝对定位(abs)与相对定位(relative) 区别是相对定位参照自己的位置进行移动(当然需要设置top left这些生效)并且原来的位置保留着 偏移后会把 其它的层遮罩住 绝对定位就是的参照位置 ...

  5. 【6】JMicro微服务-服务日志监控

    如非授权,禁止用于商业用途,转载请注明出处作者:mynewworldyyl   1. 微服务相关 在前面的1到5节中,总共涉及服务提供者,服务消费者,服务监听服务,发布订阅服务,熔断器服务5种类型的猪 ...

  6. JS常用工具函数(持续记录)

    1.设置获取cookie //方式1 //设置cookie function SetCookie(name, value)//两个参数,一个是cookie的名字,一个是值 { var Days = 3 ...

  7. 如何在Ubuntu 14.04上利用jexus搭建支持php+mysql数据库的网站服务

      准备部分:sudo apt-get update          sudo apt-get install unzip -y第一部分:安装jexus    在终端运行以下命令    cd /tm ...

  8. C#集成FastDFS断点续传

    C#集成FastDFS断点续传 参考 .net版本FastDFS客户端v5.05. https://github.com/zhouyh362329/fastdfs.client.net FastDFS ...

  9. mysql的sql执行计划详解(非常有用)

    以前没有怎么了解mysql执行计划,以及sql 优化方面,今天算学习了. https://blog.csdn.net/heng_yan/article/details/78324176 https:/ ...

  10. SSM整合(2): spring 与 mybatis 整合

    在进行完spring与springmvc整合之后, 继续 spring与mybatis的整合. 既然是操作数据库, 那必然不能缺少了连接属性 一. db.properties jdbc.driver= ...