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. 03使用Want Weapp进行路由跳转

    因为这里使用的是第三方库,所以你要引入哈. 在app.json中引入哈. "usingComponents": { "van-cell": "@van ...

  2. C语言输出菱形

    #include<stdio.h> #include<string.h> int main(){          int data[7][7] = {0};     for( ...

  3. openpyxl 模块 读写Excel

    import openpyxl #写到execl中def write_execl(): book=openpyxl.Workbook() sheet=book.active #获取默认sheet # ...

  4. Java 方法之形参和实参 、堆、栈、基本数据类型、引用数据类型

    * 形式参数:用于接收实际参数的变量(形式参数一般就在方法的声明上) * 实际参数:实际参与运算的变量 * 方法的参数如果是基本数据类型:形式参数的改变不影响实际参数. * * 基本数据类型:byte ...

  5. "二号标题"组件:<h2> —— 快应用组件库H-UI

     <import name="h2" src="../Common/ui/h-ui/text/c_h2"></import> < ...

  6. Anaconda下的juputer notebook 更改起始目录的方法【填坑】

    出来的结果是这样的,我们很不习惯,找文件.保存文件很麻烦 这里的快捷方式可以打开 jupyter notebook ,但是如果你没配置环境变量的话,在cmd 中 输入命令 jupyter notebo ...

  7. [leetcode]1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree

    [leetcode]1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree 链接 leetcode 描述    ...

  8. 【特征检测】BRISK特征提取算法

    [特征检测]BRISK特征提取算法原创hujingshuang 发布于2015-07-24 22:59:21 阅读数 17840 收藏展开简介        BRISK算法是2011年ICCV上< ...

  9. 黑猫关键词URL采集工具 Pro v1.0

    功能介绍:黑猫关键词URL采集工具 Pro v1.0 批量关键词自动搜索采集 自动去除垃圾二级泛解析域名 可设置是否保存域名或者url 联系客服QQ:944520563

  10. CAS原理解析

    CAS底层原理 概念 CAS的全称是Compare-And-Swap,它是CPU并发原语 它的功能是判断内存某个位置的值是否为预期值,如果是则更改为新的值,这个过程是原子的 CAS并发原语体现在Jav ...