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. OSLab多进程

    日期:2019/3/23 内容:Linux下与多进程相关的函数.     进程基本知识 定义 应用程序关于某数据集合上的一次运行活动. 特点 ·操作系统进行资源分配和调度的基本单位 ·进程是程序的一次 ...

  2. Java Calender 类详解

    一.   如何创建 Calendar 对象 Calendar 是一个抽象类, 无法通过直接实例化得到对象. 因此, Calendar 提供了一个方法 getInstance,来获得一个Calendar ...

  3. 【文文殿下】[APIO2010]特别行动队 题解

    基本上是一个斜率优化裸题了 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int max ...

  4. MariaDB 存储过程与函数(10)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  5. 【Spark调优】:RDD持久化策略

    [场景] Spark对RDD执行一系列算子操作时,都会重新从头到尾计算一遍.如果中间结果RDD后续需要被被调用多次,可以显式调用 cache()和 persist(),以告知 Spark,临时保存之前 ...

  6. @transactional作用和事务

    今天在博客园看到有发布spring的注解,留意到@transactional这个注解.立马就百度.学习了 使用这个注解的类或者方法表示该类里面的所有方法或者这个方法的事务由spring处理,来保证事务 ...

  7. mongodb postgresql mysql jsonb对比

    mongodb pg mysql jsonb对比 http://erthalion.info/2017/12/21/advanced-json-benchmarks/ 使用禁用jsonb列的压缩 AL ...

  8. 在没有任何投票节点情况下将从节点转换为Primary节点脚本

    cfg={ "_id": "rs01", "version": 2, "protocolVersion": Number ...

  9. IQueryable与IEnumerable

    IEnumerable: 从服务器处取回所有数据,在客户端根据过滤条件进行过滤再返回结果. IQueryable: 从服务器处进行过滤,直接返回过滤后的结果.

  10. Java 并发优化

    线程不安全 SimpleDateFormat不是线程安全的 SimpleDateThread import java.text.ParseException; import java.text.Sim ...