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. java中的动手动脑

    1.关于构造函数的问题 为什么上面的代码不能通过编译? 因为当你没有定义构造函数时,java编译器在编译时会自动生成一个无参的构造函数,上面的代码就可以进行执行了.但是当你顶一个构造函数时,编译器将不 ...

  2. MTK Android Driver :Memory

    型号配置: 1.CUSTOM_MEMORY_HDR(需要确认是否是MTK认证的flash ic) mediatek\custom\$(PROJECT)\preloader\inc\custom_Mem ...

  3. C语言 文件操作(一)

    #include<stdio.h> int main(){          FILE *fp = fopen("f:\\lanyue.txt","r&quo ...

  4. vscode如何安装eslint插件 代码自动修复

    ESlint:是用来统一JavaScript代码风格的工具,不包含css.html等. 方法和步骤: 通常情况下vue项目都会添加eslint组件,我们可以查看webpack的配置文件package. ...

  5. PHP获取当天、本周、本月、本季度、本年度时间

    function get_date($date, $t = 'd', $n = 0) { if ($t == 'd') { $firstday = date('Y-m-d 00:00:00', str ...

  6. Array(数组)对象-->lastIndexOf() 方法

    1.定义和用法 lastIndexOf() 方法可返回一个指定的字符串值最后出现的位置,如果指定第二个参数 start,则在一个字符串中的指定位置从后向前搜索. 语法: string.lastInde ...

  7. tf.nn.bias_add 激活函数

    tf.nn.bias_add(value,bias,data_format=None,name=None) 参数: value:一个Tensor,类型为float,double,int64,int32 ...

  8. 【公益线上自习室】不连麦,无微信群,无qq群

    马上就要到5月了,从刚开始的放纵已经逐渐变得慌乱. 疫情还没有完全过去,居家学习.工作是最好的选择. 但是,问题是,在家太舒服了,一点也不想学习. 一开始“哈哈哈哈哈哈哈哈”朋友了,现在已经开始“唉… ...

  9. python初学(三)

    1.以软科中国最好大学排名为分析对象,基于requests库和bs4库编写爬虫程序,对2015年至2019年间的中国大学排名数据进行爬取,并按照排名先后顺序输出不同年份的前10位大学信息,要求对输出结 ...

  10. D3.js 力导向图的拖拽(drag)与缩放(zoom)

    不知道大家会不会跟我一样遇到这样的问题,在之前做的力导向图的基础上加上缩放功能的时候,拖动节点时整体会平移不再是之前酷炫的效果(失去了拉扯的感觉!).天啊,简直不能接受如此丑X的效果.经过不懈的努力终 ...