POJ2247,hdu1058(Humble Numbers)
Write a program to find and print the nth element in this sequence
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
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)的更多相关文章
- php实现把数组排成最小的数(核心是排序)(看别人的代码其实也没那么难)(把php代码也看一下)(implode("",$numbers);)(usort)
php实现把数组排成最小的数(核心是排序)(看别人的代码其实也没那么难)(把php代码也看一下)(implode("",$numbers);)(usort) 一.总结 核心是排序 ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数006, image,影像处理(像素图)
<zw版·Halcon-delphi系列原创教程> Halcon分类函数006, image,影像处理(像素图) 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“* ...
- RGB图像数据字符叠加,图像压缩(ijl库),YUV转RGB
jackyhwei 发布于 2010-01-01 12:02 点击:3218次 来自:CSDN.NET 一些非常有用的图像格式转换及使用的源代码,包括RGB图像数据字符叠加,图像压缩(ijl库),Y ...
- gcc “-I”(大写i),“-L”(大写l),“-l”(小写l)的区别
我们用gcc编译程序时,可能会用到“-I”(大写i),“-L”(大写l),“-l”(小写l)等参数,下面做个记录: 例: gcc -o hello hello.c -I /home/hello/inc ...
- [原创].NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇)
原文:[原创].NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇) .NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇) 前言:接着上篇来. 系列文章链接: [ ...
- Java四种排序:冒泡,选择,插入,二分(折半插入)
四种排序:冒泡,选择,插入,二分(折半插入) public class Test{ // public static void main(String[] args) { // Test t=new ...
- 程序员必知的8大排序(四)-------归并排序,基数排序(java实现)
程序员必知的8大排序(一)-------直接插入排序,希尔排序(java实现) 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现) 程序员必知的8大排序(三)-------冒 ...
- 程序员必知的8大排序(三)-------冒泡排序,快速排序(java实现)
程序员必知的8大排序(一)-------直接插入排序,希尔排序(java实现) 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现) 程序员必知的8大排序(三)-------冒 ...
- 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现)
程序员必知的8大排序(一)-------直接插入排序,希尔排序(java实现) 程序员必知的8大排序(二)-------简单选择排序,堆排序(java实现) 程序员必知的8大排序(三)-------冒 ...
- 学习 Linux,302(混合环境): Samba 角色
http://www.ibm.com/developerworks/cn/linux/l-lpic3-310-2/ 概述 在本文中,了解下列概念: Samba 安全模式 核心 Samba 守护程序的角 ...
随机推荐
- [Caddy2] 无法访问 Lets Encrypt OCSP 的解决方法
更换国内 DNS 为国外 DNS. Caddy 使用对应 DNS 的 provider. 重新运行即可获取到证书,Certificate obtained successfully. 其它参考: [C ...
- dotnet C# 获取当前设备可移动磁盘
本文告诉大家如何获取当前设备的可移动磁盘 在我的 WPF 应用里面,期望获取到 U 盘的所在盘进行一些有趣的逻辑.可以通过 DriveInfo 类的 GetDrives 获取当前所有的驱动器磁盘 再通 ...
- LVGL 定时器
LVGL 8.0 以后好像取消了自定义任务模块,想要使用多线程只能使用系统的线程. 一.定时器结构体 typedef struct _lv_timer_t { uint32_t period; // ...
- Ollama开发指南
安装必备工具 确保已安装以下软件的正确版本: CMake 3.24 或更高版本 Go 1.22 或更高版本 GCC 11.4.0 或更高版本 使用 Homebrew 安装这些工具(适用于macOS和L ...
- R1_ES知识图谱
业务量增加,优化..优化... 学习... 学习..... 阮一鸣,eBay Pronto 平台技术负责人,管理了 eBay 内部上百个 Elasticsearch 集群,数据规模超过 4000 节点 ...
- anaconda安装cv2库
在安装cv2库之前,需要进行以下准备工作: 安装Anaconda 如果还没有安装Anaconda,可以在官网上下载对应操作系统的Anaconda安装包,然后按照提示进行安装.安装完成后,可以在终端中输 ...
- IPv6 — 综合组网技术
目录 文章目录 目录 前文列表 IPv4v6 综合组网技术(转换机制) 双栈策略 隧道策略 前文列表 <IPv6 - 网际协议第 6 版> <IPv6 - 地址格式与寻址模式> ...
- 京东面试:SpringBoot同时可以处理多少请求?
Spring Boot 作为 Java 开发中必备的框架,它为开发者提供了高效且易用的开发工具,所以和它相关的面试题自然也很重要,咱们今天就来看这道经典的面试题:SpringBoot同时可以处理多少个 ...
- git 安装 和 git 客户端的使用
git clone 命令 # 查前当前登录用户的一些基本信息: # 查看当前登录的账号:git config user.name # 修改当前登录的账号为xcj:git config --global ...
- Linux之top命令分析
第一行: top - 04:25:26 当前系统时间 up 3 min, 系统已经运行的时间(不间歇的运行) 1 user, 当前登录系统的用户数 load average: 0.01, 0.03, ...