Humble Numbers(hdu1058)
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14047 Accepted Submission(s): 6108
Write a program to find and print the nth element in this sequence
如果一个数的质因子只有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 ;
}
Humble Numbers(hdu1058)的更多相关文章
- 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, ...
- 【CF55D】Beautiful numbers(动态规划)
[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...
- hdu 1058:Humble Numbers(动态规划 DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 【USACO 3.1】Humble Numbers(给定质因子组成的第n大的数)
题意:给你k(≤100)个质数,求质因子只包含它们的第n大的数. 题解: 方法一:维护一个数组,一开始只有给出的质数在里面,用每个质数去乘以数组中每个数,然后归并排序,长度保留到n,一轮接一轮,直到乘 ...
- Round Numbers(组合数学)
Round Numbers Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tota ...
- 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 ...
- 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 ...
- HDU 1058 Humble Numbers(离线打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...
- 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 ...
随机推荐
- [leetcode.com]算法题目 - Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- CSS3盒子模型(上)
CSS的盒子模型分为三个大模块: 盒子模型 . 浮动 . 定位,其余的都是细节.要求这三部分,只要是学前端的无论如何也要学的非常精通. 所谓盒子模型就是把HTML页面中的元素看作是一个矩形的盒子,也就 ...
- eclipse maven打war包
在eclipse中找到pom.xml文件右键 选择debug as 再选择Maven install运行后 按路径找到生成的war包 推荐https://www.cnblogs.com/qlqwjy/ ...
- Pycharm配置autopep8:自动调整代码为PEP8风格
关于PEP 8 PEP 8,Style Guide for Python Code,是Python官方推出编码约定,主要是为了保证 Python 编码的风格一致,提高代码的可读性. 官网地址:http ...
- 文件分享系统(Django)
- Unity C# .Net List 优化点
Unity C# .Net List 优化点 已知长度 则初始化指定长度 调用多次Remove会导致内存浪费 调用TrimExcess释放多余内存 List代码实现原理 使用数组保存泛型数据 代码 L ...
- google浏览器高清壁纸保存
谷歌浏览器 扩展程序里边 有一个主题壁纸 好多不错的,并且是高清大图!!! 主题应用市场: https://chrome.google.com/webstore/category/themes?hl= ...
- Servlet 分页保存查询条件
第一种情况:一个页面走一个JSP页面和Servlet 解决办法: /** 把用户这一次选择的所有条件保存Map集合中,再把 map存到Session会话中,点击分页时进入将Servlet中再将Sess ...
- nginx反向代理如何获取真实IP?
由于客户端和web服务器之间增加了中间层,因此web服务器无法直接拿到客户端的ip,通过$remote_addr变量拿到的将是反向代理服务器的ip地址. 1.安装--with-http_realip_ ...
- java入门,学习笔记
编译 通过javac编译java程序,会编译出一个后缀为class的文件,我们再通过java虚拟机(jvm)执行编译后的java程序. 在java中始终有一个main函数,它作为程序的入口,程序从这个 ...