HDU Problem D [ Humble number ]——基础DP丑数序列
Problem D
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 7 Accepted Submission(s) : 3
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.
#include<iostream>
#include<queue>
#include<set>
#include<cstdio>
using namespace std;
set<long long int>a;
vector<long long int>c;
void js()
{
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(4);
a.insert(5);
a.insert(6);
a.insert(7);
set<long long int>::iterator poi;
for(poi=a.begin();;poi++)
{
a.insert(2**poi);
a.insert(3**poi);
a.insert(5**poi);
a.insert(7**poi);
if(a.size()>6800)break;
}
for(poi=a.begin();poi!=a.end();poi++)
{
c.push_back(*poi);
}
}
string fuhao(int a)
{
if(a%100==11) return "th";
else if(a%100==12) return "th";
else if(a%100==13) return "th";
else if(a%10==1) return "st";
else if(a%10==2) return "nd";
else if(a%10==3) return "rd";
else return "th";
}
int main()
{
js();
int N;
while(scanf("%d",&N)&&N)
cout<<"The "<<N<<fuhao(N)<<" humble number is "<<c[N-1]<<'.'<<endl;
}
HDU Problem D [ Humble number ]——基础DP丑数序列的更多相关文章
- LeetCode OJ:Ugly Number II(丑数II)
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- 【Leetcode】264. Ugly Number II ,丑数
原题 Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime facto ...
- hdu 1003 Max Sum(基础dp)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- hdu 5623 KK's Number(dp)
问题描述 我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N\left(1\leq N\leq 5*{10}^{4} \right)N(1≤N≤5∗104)个数,每次KK都会先拿数.每 ...
- HDU 1069 Monkey and Banana 基础DP
题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...
- HDU 1003 基础dp 最大连续序列和
常常做错的一道题.. 因为总是要有一个长度的 所以一开始的s与e都是1 maxx也是a[1] 然后再求 从i=2开始 在这里注意 me永远是当前i 而ms则可能留在原地 可能直接等于i 判断条件就是当 ...
- LeetCode OJ 之 Ugly Number II (丑数-二)
题目: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime fact ...
- 264. Ugly Number II(丑数 剑指offer 34)
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- Ugly number丑数2,超级丑数
[抄题]: [思维问题]: [一句话思路]:Long.valueOf(2)转换为long型再做 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图 ...
随机推荐
- Kafka,RocketMQ,RabbitMQ部署与使用体验
前言 近期在研究各种消息队列方案,为了有一个直观的使用体验,我把Kafka,RocketMQ,RabbitMQ各自部署了一遍,并使用了最基本的生产与消费消息功能.在部署过程中也遇到一些问题,特此记录. ...
- c++用递归法将一个整数n转换成字符串
任务描述 用递归法将一个整数n转换成字符串.例如,输入483,应输出字符串“483”.n的位数不确定,可以是任意位数的整数. 测试输入: 预期输出: 程序源码: #include <stdio. ...
- JS 浏览器BOM-->open() 方法
1.定义和用法 open() 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口. 语法: window.open(URL,name,specs,replace) 参数: URL:打开指定的页面的U ...
- tf.nn.relu 激活函数
tf.nn.relu(features, name = None) 计算校正线性:max(features, 0) 参数: features:一个Tensor.必须是下列类型之一:float32,fl ...
- Weblogic-SSRF 漏洞复现
0x01 环境搭建 我这里使用的是vulhub,它几乎包含了所有的漏洞环境.(建议安装在ubuntu上) 有需要的小伙伴来企鹅群自取. 安装好vulhub之后需要cd 到weblogic ssrf 目 ...
- AJ整理问题之:内存堆栈
内存 数据在内存中的存放 在计算机中,运行的应用程序的数据都是保存在内存中的. 不同类型的数据,保存的内存区域不同,其中包括: 1:栈区(stack)由编译器自动分配并释放,一半存放函数的参数值,局部 ...
- Delphi TMemo 可以显示、编辑多行文本
多行编辑框组件(TMemo)TMemo组件可以显示.编辑多行文本,是一个标准的Windows多行编辑组件.对一些比较多的文本内容可以利用TMemo组件来显示.编辑. 1.TMemo组件的典型用法 TM ...
- Oracle使用fy_recover_data恢复truncate删除的数据
(一)truncate操作概述 在生产中,truncate是使用的多的命令,在使用不当的情况下,往往会造成表的数据全部丢失,恢复较为困难.对于truncate恢复,常见的有以下几种方法可以进行恢复: ...
- 【半译】在ASP.NET Core中创建内部使用作用域服务的Quartz.NET宿主服务
在我的上一篇文章中,我展示了如何使用ASP.NET Core创建Quartz.NET托管服务并使用它来按计划运行后台任务.不幸的是,由于Quartz.NET API的工作方式,在Quartz作业中使用 ...
- 7.关于一些dom&&获取元素
1. 测试点击的是否是span 标签 <span onClick={this.select.bind(this)}>点击</span> select( e ){ cons ...