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 ...
随机推荐
- shell实例浅谈之六文件特定行打印的多种方法
一.问题 Sed和AWK在处理文件方面有很强的优势,还有head和tail等文件处理工具的使用,grep也可实现文本的搜索.上述命令都可以在后面直接加文件名,不需要在前面使用cat添加管道,cat会影 ...
- C和C++安全编码读书笔记1
(1)type safety Another characteristic of C that is worth mentioning is the lack of type safety. Type ...
- Nginx阅读笔记(三)之proxy_pass用法
在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走,如果没有/,则会把匹配的路径部分也给代理走. 假设访问 ...
- Unable to connect to your virtual device!解决方法
使用Genymotion安卓模拟器的用户,很多朋友在启动安卓系统的时候就弹出了以下英文,不知道如何处理,今天电脑知识网小编来教您处理Genymotion安卓模拟器启动出错的问题. Error Unab ...
- 国际名品SYSTEM入驻北京金融街购物中心__购物败家_YOKA时尚网
国际名品SYSTEM入驻北京金融街购物中心__购物败家_YOKA时尚网 国际名品SYSTEM入驻北京金融街购物中心
- 【Cocos2d-X开发学习笔记】第03期:渲染框架之导演类(CCDirector)的使用
本系列学习教程使用的是cocos2d-x-2.1.4版本(截至目前为止最新稳定版) ,PC开发环境Windows7,C++开发环境VS2010 提到“导演”一词,想必读者最先联想到的是电影.作为娱乐产 ...
- NAT简单介绍
NAT本质就是让一群机器公用同一个IP.还有一个重要的用途是保护NAT内的主机不受外界攻击 NAT类型: 1.Full Cone:IPport不受限 Full Cone仅仅做单纯的地址转换,不正确进出 ...
- Android Intent 解析之二
服务端Intent运行过程: Sticky:这个类型的BroadCast表示某些Intent须要被保留,当新的应用起来后,须要关注这个消息,可是呢,又不须要启动这个应用来接收此消息,比方耳机插入等消息 ...
- 如何安装系统认证签名过的APK
如果你的App因为权限原因需要设置 android:sharedUserId="android.uid.system" 那么IDE编译出的包通常是无法直接安装的,查看控制台会发现报 ...
- iOS开发中NSDate时间戳的转换--
NSTimeInterval time =(NSTimeInterval )[model.day floatValue]; NSDate *date = [NSDate dateWithTimeInt ...