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 ...
随机推荐
- Hadoop运行中遇到的错误调试
在运行Hadoop的过程中遇到的最多的问题就是DataNode不能正常的启动,各种问题都有可能,说一下我遇到的两种情况: (1)第一种情况是Master的防火墙没有关闭.这样在启动Hadoop的时候, ...
- C函数调用与栈
这篇blog试图说明这么一个问题,当一个c函数被调用时,一个栈帧(stack frame)是如何被建立,又如何被消除的.这些细节跟操作系统平台及编译器的实现有关,下面的描述是针对运行在Linux的gc ...
- Web开发找错基本思路
WEB开发主要是两个交互(B/S数据) 浏览器: 1 包含html.css.js等客户端代码运行错误. 传输端: 1 路径引入错误,常用插件的引入(artDialog.Ztree.JQuery等). ...
- ASP.NET MVC5 学习笔记-1 控制器、路由、返回类型、选择器、过滤器
[TOC] 1. Action 1.1 新建项目 新建项目->Web->Asp.net Web应用程序,选择MVC,选择添加测试. 在解决方案上右键,选择"管理NuGet程序包& ...
- background-position 个人理解
background-position这里先说像素 百分比比较复杂background-position:xxpx xxpx 这里第一个值指的是x轴坐标 第二个值是y轴坐标这里使用的坐标系和数学 ...
- QT https post请求(QNetworkRequest要设置SSL证书,而SSL证书认证有三种,实测成功)
以VS开发为例.因为https访问需要用到SSL认证,而QT默认是不支持SSL认证,所以在使用之前必须先做一些准备工作: 需要安装OpenSSL库: 1.首先打开http://slproweb.com ...
- repeater一个简单的用法例子
(前台) <asp:Repeater ID="Repeater1" runat="server" onitemdatabound=" ...
- Linux学习:find、chmod、ps命令
下面介绍下linux下find.chmod.ps这三个常见命令的使用. 这每个命令都有很多可选的参数,不同参数体现的功能不一样.我们这里不一一介绍各种参数的含义,只介绍最常见的使用场景. 一.find ...
- C++惯用法:通过成员模板实现隐式转换(Coercion 强迫 by Member Template)
Intent To increase the flexibility of a class template's interface by allowing the class template to ...
- notify()、notifyAll()和wait()
看到一道面试题,写一个多线程程序,交替输出1.2.1.2…… 先写下程序: /** * Created by Andrew on 2015/10/28. */ public class OutputT ...