HDU Humble Numbers
Write
a program to find and print the nth element in this sequence
case consists of one integer n with 1 <= n <= 5842. Input is terminated by
a value of zero (0) for n.
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.
2
3
4
11
12
13
21
22
23
100
1000
5842
0
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<stdio.h>
#include<math.h>
int main(){
long long data[5848];
int index=1,first=1,second=1,third=1,forth=1,n;
while(1){
if(index==5843)
break;
data[1]=1;
int temp,temp1,temp2;
temp1=data[first]*2<=data[second]*3?data[first]*2:data[second]*3;
temp2=data[third]*5<=data[forth]*7?data[third]*5:data[forth]*7;
temp=temp1<=temp2?temp1:temp2;
if(temp==data[first]*2)
first++;
if(temp==data[second]*3)
second++;
if(temp==data[third]*5)
third++;
if(temp==data[forth]*7)
forth++;
if(temp>data[index]){
//printf("%d ",data[index]);
data[++index]=temp;
}
}
while(~scanf("%d",&n)){
if(n==0)break;
if(n%10==1&&n%100!=11){
printf("The %dst humble number is %d.\n",n,data[n]);
}else if(n%10==2&&n%100!=12){
printf("The %dnd humble number is %d.\n",n,data[n]);
}else if(n%10==3&&n%100!=13){
printf("The %drd humble number is %d.\n",n,data[n]);
}else{
printf("The %dth humble number is %d.\n",n,data[n]);
}
}
return 0;
}
HDU Humble Numbers的更多相关文章
- hdu 1058 dp.Humble Numbers
Humble Numbers Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- HDOJ(HDU).1058 Humble Numbers (DP)
HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...
- 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 ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Humble Numbers HDU - 1058
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...
- hdu 1058:Humble Numbers(动态规划 DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1058 Humble Numbers (动规+寻找丑数问题)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- A - Humble Numbers
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- Humble Numbers(hdu1058)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- R语言扩展包dplyr笔记
引言 2014年刚到, 就在 Feedly 订阅里看到 RStudio Blog 介绍 dplyr 包已发布 (Introducing dplyr), 此包将原本 plyr 包中的 ddply() 等 ...
- Qt中delete的问题
最近项目遇到了一个bug,压力测试ui总会崩溃,gdb调试未果,跑到了库函数,无从查起: (gdb)bt #0 0x4146b1e4 in QWidgetPrivate::drawWidget(QPa ...
- Navicat连接Oracle11g 错误的解决办法
一.换成32位的Navicat!!! 二.去Oracle官网下载你要连接数据版本的client. 注意:需要下载两个文件,以11.2.0.4.0版本为例,需要下载 instantclient-sqlp ...
- 第三百一十六节,Django框架,中间件
第三百一十六节,Django框架,中间件 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的规则在合适的时机执行中间 ...
- 正则表达式”\d+\.?\d*”在匹配下列字符串时结果是失败的是?
A 12.5 B 1.25 C 以上都成功 D 以上都失败 解答:B \d+ 表示可以出现1次或是n次数字 \. .? 表示可以“.”可以出现一次,也可以不出现 \d* 表示可以出现0次或是n次数字
- Ubuntu telnet
首先在Ubuntu中安装xinetd(它是inetd替代品): sudo apt-get install xinetd 再安装telnetd,在Ubuntu中没有telnetd这个软件包,它是包含在i ...
- php十行代码将xml转成数组
<?php header("Content-Type:text/html;charset=utf-8"); function xml2array($filename){ $x ...
- Maven------使用maven新建web项目出现问题 项目名称出现红色交叉
转载: http://wenda.so.com/q/1365963640069173?src=140 解决方法: problems窗口查看到下面错误java compiler level does n ...
- swift - 表格的编辑功能(添加、删除)
表格(tableview)的确是一个很好用的控件,现在来实现一个编辑功能的实现,包含添加和删除,删除包括长按删除和左滑删除 效果图如下: 具体代码如下: 1.创建表格(这个表格有2个区,有区头和区尾) ...
- 在linux中添加环境变量
首先用命令查看配置了哪些环境变量 env命令查看 编辑环境变量命令 vim ~/.bash_profile Counter_HOME=/home/test/Counterexport Counter ...