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丑数序列的更多相关文章

  1. LeetCode OJ:Ugly Number II(丑数II)

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  2. 【Leetcode】264. Ugly Number II ,丑数

    原题 Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime facto ...

  3. hdu 1003 Max Sum(基础dp)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  4. hdu 5623 KK's Number(dp)

    问题描述 我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N\left(1\leq N\leq 5*{10}^{4} \right)N(1≤N≤5∗10​4​​)个数,每次KK都会先拿数.每 ...

  5. HDU 1069 Monkey and Banana 基础DP

    题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...

  6. HDU 1003 基础dp 最大连续序列和

    常常做错的一道题.. 因为总是要有一个长度的 所以一开始的s与e都是1 maxx也是a[1] 然后再求 从i=2开始 在这里注意 me永远是当前i 而ms则可能留在原地 可能直接等于i 判断条件就是当 ...

  7. LeetCode OJ 之 Ugly Number II (丑数-二)

    题目: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime fact ...

  8. 264. Ugly Number II(丑数 剑指offer 34)

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  9. Ugly number丑数2,超级丑数

    [抄题]: [思维问题]: [一句话思路]:Long.valueOf(2)转换为long型再做 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图 ...

随机推荐

  1. go 内置函数

    一.什么是内置函数? 二.内置函数有哪些? 名称 说明 close 用于管道通信 len.cap len 用于返回某个类型的长度或数量(字符串.数组.切片.map 和管道):cap 是容量的意思,用于 ...

  2. 使用nginx转换HTTPS流量

    背景 公司卖了一个产品给甲方,甲方要求部署后,要以https来访问.甲方提供了证书信息和私钥,记录一下部署过程. 实现 1.思路 在我们产品服务器上部署一个nginx.证书信息也放在这个服务器上.外界 ...

  3. NonRegisteringDriver造成的内存频繁FullGc

    某天上服务器看了下gc情况,发现状况不对,启动了才2天的服务器发生了360次fullgc,这个频率肯定高了 说明 S0C.S1C.S0U.S1U:Survivor 0/1区容量(Capacity)和使 ...

  4. Js异步机制的实现

    Js异步机制 JavaScript是一门单线程语言,所谓单线程,就是指一次只能完成一件任务,如果有多个任务,就必须排队,前面一个任务完成,再执行后面一个任务,以此类推.这种模式的好处是实现起来比较简单 ...

  5. 数据结构和算法(Golang实现)(8.2)基础知识-分治法和递归

    分治法和递归 在计算机科学中,分治法是一种很重要的算法. 字面上的解释是分而治之,就是把一个复杂的问题分成两个或更多的相同或相似的子问题. 直到最后子问题可以简单的直接求解,原问题的解即子问题的解的合 ...

  6. AJ学IOS 之UIDynamic重力、弹性碰撞吸附等现象

    AJ分享,必须精品 一:效果 重力和碰撞 吸附现象 二:简介 什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟和仿真 ...

  7. Git应用详解第十讲:Git子库:submodule与subtree.md

    前言 前情提要:Git应用详解第九讲:Git cherry-pick与Git rebase 一个中大型项目往往会依赖几个模块,git提供了子库的概念.可以将这些子模块存放在不同的仓库中,通过submo ...

  8. stand up meeting 11/18/2015

    今日工作总结: 冯晓云:完成C#版本API的class library编译,尝试与主程序进行通信:昨天临时通知让用C++封装,不解!!![后续:我用C#做了一个查词的APP,调用的就是这个API的DL ...

  9. 【Jenkins】参数化引用

    我们在Jenkins里设置了参数如下 1. Jenkins中引用 shell引用  $env windows bat引用 %env% 在git等源码管理时,调用参数的格式${env} 2. jmete ...

  10. 一篇文章快速搞懂Redis的慢查询分析

    什么是慢查询? 慢查询,顾名思义就是比较慢的查询,但是究竟是哪里慢呢?首先,我们了解一下Redis命令执行的整个过程: 发送命令 命令排队 命令执行 返回结果 在慢查询的定义中,统计比较慢的时间段指的 ...