HDU1058 Humble Numbers 【数论】
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.
#include <stdio.h>
#define maxn 5845 int dp[maxn] = {1, 1};
int a, b, c, d;
const char *sam[] = { "st", "nd", "rd", "th" }; int min(int u, int v, int x, int y)
{
int tmp = u;
if(tmp > v) tmp = v;
if(tmp > x) tmp = x;
if(tmp > y) tmp = y; if(tmp == u) ++a;
if(tmp == v) ++b;
if(tmp == x) ++c;
if(tmp == y) ++d; return tmp;
} const char *f(int n)
{
if(n % 10 == 1 && n % 100 != 11) return sam[0];
if(n % 10 == 2 && n % 100 != 12) return sam[1];
if(n % 10 == 3 && n % 100 != 13) return sam[2];
return sam[3];
} int main()
{
int i, n;
a = b = c = d = 1;
for(i = 2; i < maxn; ++i)
dp[i] = min(dp[a] * 2, dp[b] * 3, dp[c] * 5, dp[d] * 7);
while(scanf("%d", &n), n)
printf("The %d%s humble number is %d.\n", n, f(n), dp[n]);
return 0;
}
HDU1058 Humble Numbers 【数论】的更多相关文章
- HDU1058 - Humble Numbers
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...
- DP 60题 -3 HDU1058 Humble Numbers DP求状态数的老祖宗题目
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Humble Numbers(hdu1058)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 洛谷P2723 丑数 Humble Numbers [2017年 6月计划 数论07]
P2723 丑数 Humble Numbers 题目背景 对于一给定的素数集合 S = {p1, p2, ..., pK},考虑一个正整数集合,该集合中任一元素的质因数全部属于S.这个正整数集合包括, ...
- [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 ...
- A - Humble Numbers
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- 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 ...
随机推荐
- BZOJ 1230: [Usaco2008 Nov]lites 开关灯( 线段树 )
线段树.. --------------------------------------------------------------------------------- #include< ...
- [C#参考]byte数组和Image的相互转换
功能需求 1.把一张图片(png bmp jpeg bmp gif)转换为byte数组在内存中操作. 2.把内存中的byte数组转换成Image对象,赋值给相应的控件显示. 3.从图片byte数组得到 ...
- JPEG概述和头分析(C源码)
原创文章,转载请注明:JPEG概述和头分析(C源码) By Lucio.Yang 部分内容来自:w285868925,JPEG压缩标准 1.JPEG概述 JPEG是一个压缩标准,又可分为标准 JPE ...
- Python之路:Python 函数
一.函数式编程:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装 二. 函数的定义和使用 def 函数名(参数): ... 函数体 ... 函数的定义主要有 ...
- 17.2?Replication Implementation 复制实施:
17.2?Replication Implementation 复制实施: 17.2.1 Replication Implementation Details 17.2.2 Replication R ...
- 汇总:Linux下10款即时通讯客户端,skype
aMSN 是一款功能强大的MSN(WLM)的客户端,支持皮肤.插件.系统托盘图标.摄像头.多帐号登录.离线信息等. Pidgin 不用说了,是GNOME下的IM客户端,支持AIM, Google Ta ...
- 如何修改Sublime 侧边栏Sidebar的颜色
参考自:http://blog.csdn.net/a497393102/article/details/10563791 首先要找到 Default.sublime-theme 文件, 点击 subl ...
- iOS开发- 打包ipa,让别人设备安装你的App
一般在接外包的时候, 通常第三方须要安装你的app进行測试(这时候你的app肯定是还没传到app store之前). 这样的情况下.假设是企业账号就好办了, 随便安装.. 可是个人开发人员账号呢? 假 ...
- 轻量级数据库sqlite的接口说明
原文地址:http://www.cnblogs.com/kfqcome/archive/2011/06/27/2136999.html 一.使用流程 要使用sqlite,需要从sqlite官网下载到三 ...
- python成长之路——第六天
定义 Python 的 Class 比较特别,和我们习惯的静态语言类型定义有很大区别. 1. 使用一个名为 __init__ 的方法来完成初始化.2. 使用一个名为 __del__ 的方法来完成类似析 ...