A - Humble Numbers
Description
Write a program to find and print the nth element in this sequence
Input
of one integer n with 1 <= n <= 5842. Input is terminated by a
value of zero (0) for n.
Output
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
2
3
4
11
12
13
21
22
23
100
1000
5842
0
Sample Output
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<cstdio>
#include<string.h>
using namespace std;
const int MAXN=;
int num2=,num3=,num5=,num7=;
long long s[MAXN];
void Sort()//sort函数是用来求humble number数组的
{
s[]=;
s[num2]=,s[num3]=,s[num5]=;
long long min=s[num2]*;
int num2=,num3=,num5=,num7=;
for(int i=;i<;i++)
{ min=s[num2]*;
if(min>s[num3]*)
min=s[num3]*;
if(min>s[num5]*)
min=s[num5]*;
if(min>s[num7]*)
min=s[num7]*;
s[i]=min;
// printf("%d ",s[i]);
//printf("%d ",min);
if(min==s[num2]*)
num2++;
if(min==s[num3]*)
num3++;
if(min==s[num5]*)
num5++;
if(min==s[num7]*)
num7++;
}
}
int main()
{
int n;
Sort();
while(scanf("%d",&n)!=EOF&&n)
{
if(n%==&&n%!=&&n!=)//当时卡在n%100!=11和12,13这里了,wa了几次!
printf("The %dst humble number is ",n);
else if(n%==&&n%!=&&n!=)
printf("The %dnd humble number is ",n);
else if(n%==&&n%!=&&n!=)
printf("The %drd humble number is ",n);
else printf("The %dth humble number is ",n);
printf("%lld.\n",s[n-]);
}
return ;
}
A - Humble Numbers的更多相关文章
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- HDU - The number of divisors(约数) about Humble Numbers
Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Humble Numbers
Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9988 Accepted: 4665 Descri ...
- 洛谷P2723 丑数 Humble Numbers
P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDOJ 1058 Humble Numbers(打表过)
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- The number of divisors(约数) about Humble Numbers
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- HDU1058 Humble Numbers 【数论】
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- android sdcard信息获取
手机存储都有两种,一种是 手机自带的存储,称为internal storage,另外一种用户额外插入的存储,称为removable storage (也就是外置sdcard的部分). removabl ...
- 参考:(Java Selenium)Element is not visible to clcik
1.The element is not visible to click. Use Actions or JavascriptExecutor for making it to click. By ...
- oracle组查询
概念: 所谓组查询即将数据按照某列或者某些列相同的值进行分组,然后对该组的数据进行组函数运用,针对每一组返回一个结果. note: 1.组函数可以出现的位置: select子句和having 子句 2 ...
- [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序使用异步及存储过程
这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第九篇:为ASP.NET MVC应用程序 ...
- CentOS6.5 安装 jdk1.7
1.卸载centos自带的jdk # rpm -qa | grep java 结果大致为: tzdata-java-2012c-1.el6.noarch java-1.7.0-openjdk-1.7. ...
- Nginx模块之————RTMP模块在Ubuntu上以串流直播HLS视频
Nginx的安装在Ubuntu上以串流直播HLS视频 https://www.vultr.com/docs/setup-nginx-on-ubuntu-to-stream-live-hls-video
- GridFS图片
-----------2016-5-9 18:58:56-- source:GridFS实现图片的存取
- 今天的感悟,对于python中的list()与w3c教程
首先本来想百度一下python定义列表的时候用 list()与直接用[]有什么区别,其中没有找到相关直接资料,看到了W3c菜鸟教程中之前看到的tuple,不禁想起list(tuple)是用来将元组转换 ...
- Android系统架构-----Android的系统体系架构
一.Android的系统体系结构 在入门了一个简单的Android的Hello World以后,我们首先来看一下我们Android的整体系统架构图: 这个就是我们Android的整体系统架构图了,我们 ...
- mysql查询结果导出到文件
方法一: 直接执行命令: mysql> select count(1) from table into outfile '/tmp/test.xls'; Query OK, 31 rows ...