Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16312 Accepted Submission(s): 7082
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
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.
题意:
也同样是找第 N 个丑数。质因子只允许是 2, 3, 5, 7。
思路:
与 USACO 那题一样。坑爹的地方在于输出,第1,2,3 个要输出 st,nd,rd。但是 11,12,13 却不用,判断的时候应该判断 n % 10 == 1 && n % 100 != 11 这样子判断。并且结果要离线处理好。
AC:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const ll INF = 5000000000; int p[5], f[5]; ll hum[6000]; void solve () { p[1] = 2, p[2] = 3, p[3] = 5, p[4] = 7; for (int i = 1; i <= 4; ++i) f[i] = 1; hum[1] = 1; for (int k = 2; k <= 5842; ++k) { ll Min = INF; for (int i = 1; i <= 4; ++i) { while (p[i] * hum[ f[i] ] <= hum[k - 1]) ++f[i]; Min = min(Min , p[i] * hum[ f[i] ]); } hum[k] = Min; } } int main() { solve(); int n; while (~scanf("%d", &n) && n) { printf("The %d", n); if (n % 10 == 1 && n % 100 != 11) printf("st "); else if (n % 10 == 2 && n % 100 != 12) printf("nd "); else if (n % 10 == 3 && n % 100 != 13) printf("rd "); else printf("th "); printf("humble number is %lld.\n", hum[n]); } return 0; }
相关推荐
【标题解析】:“Humble Numbers 简单DP”这个标题指的是一个与“Humble Numbers”相关的编程问题,它可以通过动态规划(Dynamic Programming, DP)方法来解决。Humble Numbers,也称为卑微数,是一类特殊的自然数,...
ros humble的key
- BFS在此处的作用是扩展已有的Humble Numbers序列,而Treap用于快速查找、插入新生成的Humble Numbers,并判断是否存在重复。 - 此方法的优势在于能够显著减少不必要的重复检查,提高效率。 - **方法三**: - ...
《The Humble Programmer》是荷兰计算机科学家艾兹赫尔·戴克斯特拉(Edsger W. Dijkstra)在1972年美国计算机协会图灵奖颁奖典礼上所做的演讲。在演讲中,戴克斯特拉回顾了自己的编程生涯,并探讨了编程作为一种...
如果使用Maven,则将Humble部署到Maven中央存储库。 要将其包含在您的项目中(请注意:这将包括所有操作系统的工件),请将其添加到pom.xml中: ... ... < groupId>io.humble < artifactId>humble-video-...
### 《谦卑的程序员》—— Edsger W. Dijkstra 的 1972 图灵奖演讲 #### 概述 《谦卑的程序员》是计算机科学领域著名人物 Edsger W....该文首次发表在《ACM 通讯》上,后被广泛引用和传播,对软件工程、编程哲学以及...
这个资源,"humble-0.1.2.tar.gz",是PyPI上一个名为"humble"的Python库的版本0.1.2的压缩包文件。 在Python开发中,使用第三方库可以极大地提高开发效率,而PyPI正是这样一个平台,开发者可以将自己编写的Python...
com.humble.SlayTheSpire.apk
ros2-humble串口通信serial库
A_humble_SublimeText_package_for_exporting_highlig_SublimeHighlight
Python脚本提取所有Humble键并自动在Steam上赎回它们。 这主要是设计成一种“设置后忘”的工具,可以最大程度地成功将密钥输入Steam,从而确保不会赎回Steam游戏。 该脚本将同时登录Humble和Steam,从而使整个过程...
Humble是一组松散耦合的工具,旨在使用go和构建客户端和混合Web应用程序。 Humble专为编写前端代码而设计,完全与后端无关。 您可以将Humble与以任何语言编写的任何后端服务器结合使用。 如果您确实选择同时编写...
Humble Key Restriction 描述 查看 Humble Bundle Key 的激活激活限制插件 它能帮你在 Humble 的 Download 界面显示 Key 的激活限制信息。 安装 安装 (推荐)、 或者其它用户脚本管理工具 安装脚本 就可以用啦 XD ...
micro-ros-setup-humble.zip
如果您有兴趣签出最新的书籍捆绑包(如果有),只需单击Humble Bundle主页顶部的“书籍捆绑包”标签。 例如常规捆绑包,将有多个层次。 顶层将显示可用于“按需支付”的内容。 下面是“超越平均水平”(绿色)层,...
"Atom-atom-humble-colors-syntax.zip" 文件是一个专门为Atom设计的语法主题,名为"Humble Colors Syntax"。 语法主题是编辑器中的一个重要组成部分,它决定了代码在编辑器中的颜色显示方式。"Humble Colors Syntax...
《Humble_Pal:自动化与跟踪,提升Humble Bundle体验》 Humble_Pal是一款针对Humble Bundle平台的增强工具,旨在通过自动化和跟踪技术,为用户带来更加便捷和丰富的使用体验。Humble Bundle,一个知名的数字商品...
ros2humble使用gazebo加载urdf文件的基本流程.html
从Humble Bundle库中下载所有内容! 第一次运行可能需要一段时间,因为它将下载所有内容。 之后,它将仅下载已更新或丢失的内容。 产品特点 支持Humble Trove (-- --trove标志) 每次运行时从您的Humble Bundle...
做的很辛苦, 里面附有注释,大家支持一下吧...