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. 6.翻译:EF基础系列---什么是EF中的实体?

    原文地址:http://www.entityframeworktutorial.net/basics/what-is-entity-in-entityframework.aspx EF中的实体就是继承 ...

  2. 企业项目开发--cookie(2)

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 2.1.3.CookieUtil:(cookie的基本操作:增删查,注意没有改)  1 package co ...

  3. FWT学习笔记

    FWT学习笔记 引入 一般的多项式乘法是这样子的: \(c_i=\sum_{i,j}a_j*b_k*[j+k==i]\) 但是如果我们将这个乘法式子里面的+号变换一下变成其他的运算符号呢? \(c_i ...

  4. [Ynoi2018]未来日记(分块)

    分块神题. 看了一会儿题解,看懂了思路,然后写了两个小时,调了一个多小时,好多地方写错了. 我们考虑对序列和值域都分块.\(sum1[i][j]\) 表示前 \(i\) 个块,第 \(j\) 块值域有 ...

  5. js中获取当前页面的url

    在js中可以通过下面的方式获取当前页面url的相关信息 var item = window.location // 返回的是对象, 这个对象里有各种关于url的信息 var url = window. ...

  6. 2018宁夏邀请赛网赛 I. Reversion Count(java练习题)

    题目链接 :https://nanti.jisuanke.com/t/26217 Description: There is a positive integer X, X's reversion c ...

  7. 【spring cloud】服务启动后正常,但是无法上线,一直处于down状态

    spring cloud eureka 如果出现某个应用实例 down(1), 说明 spring admin 健康检测没有通过导致 eureka 注册中心不会把这个实例从列表中删除掉. 这样所有使用 ...

  8. Jmeter保存时,完美解决提示的“拒绝访问”

    使用Jmeter时,想保存测试计划,提示"拒绝访问“,这是为啥? 因为给Jmeter的权限不够,也就是说,在打开它的时候,直接双击打开,没有选择”以管理员身份运行“,就会导致”拒绝访问“ ! ...

  9. odoo开发笔记 -- 前端开发相关

    https://www.cnblogs.com/lyzg/p/5634565.html http://dmyz.org/archives/598 https://www.jianshu.com/p/6 ...

  10. idea 运行scala代码 报错:Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$ java.lang.NoClassDefFoundError: scala/Function0 Error: A JNI error has occurred, please check your installati

    各种报错信息如下: java.lang.NoClassDefFoundError: scala/Function0 at java.lang.Class.getDeclaredMethods0(Nat ...