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.
题意:寻找第n个humble number(百度翻译貌似是谦虚的数。。。什么破玩意儿?!!?!),humble number的定义为一个质因数为2或3或5或7的整数而且1也包括在内。当然比较坑的地方就是输出格式,关于输出st,nd,rd这几个单词的时候要注意,最后两位是十几的情况下只能用th,因为11是eleventh,12是twelvth,13是thirth(好吧,貌似写错别字了,估计四级又要不过)。
思路:看我之前的ugly number的题解。。。
http://blog.csdn.net/ecjtuacm_yuewei/article/details/42365475(好吧,任性了),其实这两道题目很相似的。。。懂?!
代码:
//hdu1058
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define maxn 6000
using namespace std;
__int64 biao[maxn]; inline __int64 min(__int64 x, __int64 y)
{
return x < y?x:y;
} int main()
{
int er = 1, san = 1, wu = 1, qi = 1;
biao[1] = 1;
for(int i = 2; i <= 5845; i ++)
{
biao[i] = min(min(biao[er] * 2, biao[san] * 3), min(biao[wu] * 5, biao[qi] * 7));
if(biao[i] == biao[er] * 2) er ++;
if(biao[i] == biao[san] * 3) san ++;
if(biao[i] == biao[wu] * 5) wu ++;
if(biao[i] == biao[qi] * 7) qi ++;
} // for(int i = 1; i <= 20; i ++)
// cout << biao[i] << ' '; int n;
while(cin >> n && n)
{
int k = n % 10;
int w = n / 10 % 10;
if(k == 1 && w != 1)
{
printf("The %dst humble number is %I64d.\n", n, biao[n]);
}
else if(k == 2 && w != 1)
{
printf("The %dnd humble number is %I64d.\n", n, biao[n]);
}
else if(k == 3 && w != 1)
{
printf("The %drd humble number is %I64d.\n", n, biao[n]);
}
else
{
printf("The %dth humble number is %I64d.\n", n, biao[n]);
}
}
return 0;
}

POJ2247,hdu1058(Humble Numbers)的更多相关文章

  1. php实现把数组排成最小的数(核心是排序)(看别人的代码其实也没那么难)(把php代码也看一下)(implode("",$numbers);)(usort)

    php实现把数组排成最小的数(核心是排序)(看别人的代码其实也没那么难)(把php代码也看一下)(implode("",$numbers);)(usort) 一.总结 核心是排序 ...

  2. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数006, image,影像处理(像素图)

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数006, image,影像处理(像素图) 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“* ...

  3. RGB图像数据字符叠加,图像压缩(ijl库),YUV转RGB

    jackyhwei 发布于 2010-01-01 12:02 点击:3218次  来自:CSDN.NET 一些非常有用的图像格式转换及使用的源代码,包括RGB图像数据字符叠加,图像压缩(ijl库),Y ...

  4. gcc “-I”(大写i),“-L”(大写l),“-l”(小写l)的区别

    我们用gcc编译程序时,可能会用到“-I”(大写i),“-L”(大写l),“-l”(小写l)等参数,下面做个记录: 例: gcc -o hello hello.c -I /home/hello/inc ...

  5. [原创].NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇)

    原文:[原创].NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇) .NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇) 前言:接着上篇来. 系列文章链接: [ ...

  6. Java四种排序:冒泡,选择,插入,二分(折半插入)

    四种排序:冒泡,选择,插入,二分(折半插入) public class Test{ // public static void main(String[] args) { // Test t=new ...

  7. 程序员必知的8大排序(四)-------归并排序,基数排序(java实现)

    程序员必知的8大排序(一)-------直接插入排序,希尔排序(java实现) 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现) 程序员必知的8大排序(三)-------冒 ...

  8. 程序员必知的8大排序(三)-------冒泡排序,快速排序(java实现)

    程序员必知的8大排序(一)-------直接插入排序,希尔排序(java实现) 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现) 程序员必知的8大排序(三)-------冒 ...

  9. 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现)

    程序员必知的8大排序(一)-------直接插入排序,希尔排序(java实现) 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现) 程序员必知的8大排序(三)-------冒 ...

  10. 学习 Linux,302(混合环境): Samba 角色

    http://www.ibm.com/developerworks/cn/linux/l-lpic3-310-2/ 概述 在本文中,了解下列概念: Samba 安全模式 核心 Samba 守护程序的角 ...

随机推荐

  1. dotnet 6 精细控制 HttpClient 网络请求超时

    本文告诉大家如何在 dotnet 6 下使用 HttpClient 更加精细的控制网络请求的超时,实现 HttpWebRequest 的 ReadWriteTimeout 功能 本文将介绍如何在 Ht ...

  2. win10 uwp 使用 XamlTreeDump 获取 XAML 树元素内容

    本文来安利大家 XamlTreeDump 库,通过这个库可以将 XAML 树上的元素转换为 json 字符串,可以用来进行 UI 单元测试 开始之前先通过 NuGet 工具安装 XamlTreeDum ...

  3. 超级好用的 IEC104 主站/客户端模拟器

    目录 超级好用的 IEC104 主站/客户端模拟器 主要功能 软件截图 超级好用的 IEC104 主站/客户端模拟器 官网下载地址:http://www.redisant.cn/iec104clien ...

  4. 老外为了在MacBook上玩原神,让M1支持了所有iOS应用 | Github每周精彩分享第一期

    大家好,这里是每周更新的Github有趣项目分享,我是每周都在吃瓜的蛮三刀酱. 我会从Github热门榜里选出 高质量.有趣,牛B 的开源项目进行分享. 废话不多说,看看最近有什么有意思的Github ...

  5. Notion API中Internal Notion integrations和Public Notion integrations的区别

    Internal Notion integrations Internal Notion integrations与一个单一的.特定的工作区相联系,只有该工作区的成员可以使用这个integration ...

  6. 九、.net core(.NET 6)添加通用的Redis功能

     .net core 编写通用的Redis功能 在 Package项目里面,添加包:StackExchange.Redis: 在Common工具文件夹下,新建 Wsk.Core.Redis类库项目,并 ...

  7. 80x86汇编—寻址方式

    文章目录 术语解释 8086寻址方式 直数寻址 寄存器间接寻址 寄存器相对寻址 基址变址寻址 比例变址寻址方式 基址比例变址寻址方式 术语解释 EA:有效地址,通过段地址:偏移地址组合得到的Effec ...

  8. 4G 信令中的 PCO 字段

    目录 文章目录 目录 Protocol Configuration Option Protocol Configuration Option PCO(Protocol Configuration Op ...

  9. 4G EPS 中的 User Plane

    目录 文章目录 目录 前文列表 用户平面 EPS UP 中的 GTP-U F-TEID 的组成 UE IP 数据包在 GTP-U Tunnel 上的封装流程 GTP-U 与 EPS Bearer MM ...

  10. Chart.js (v2.9.4)概要介绍

    chart.js是一个非常优秀的开源图表插件,扩展非常灵活,同时也提供了大量的钩子函数,给与用户添加自定义插件,实现个性化的需求. 具体的优势特点,这里不详述,网上大把资料,现开始正式深入了解这个插件 ...