POJ 2247 Humble Numbers
Write a program to find and print the nth element in this sequence.
Input
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. 打个表,注意输出格式
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
#include<deque>
using namespace std;
typedef long long LL;
const int maxn = 1e4+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
//#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1
typedef long long ll;
#define N 100010 int dp[]; void init(){
dp[]=;
int p2,p3,p5,p7;
p2=p3=p5=p7=;
int cnt=;
while(cnt<=){
dp[cnt]=min(dp[p2]*,min(dp[p3]*,min(dp[p5]*,dp[p7]*)));
if(dp[cnt]==*dp[p2]) p2++;
if(dp[cnt]==*dp[p3]) p3++;
if(dp[cnt]==*dp[p5]) p5++;
if(dp[cnt]==*dp[p7]) p7++;
cnt++; }
}
int main(){
init();
int n;
while(scanf("%d",&n)&&n){
if(n%==&&n%!=) printf("The %dst humble number is %d.\n",n,dp[n]);
else if(n%==&&n%!=) printf("The %dnd humble number is %d.\n",n,dp[n]);
else if(n%==&&n%!=) printf("The %drd humble number is %d.\n",n,dp[n]);
else printf("The %dth humble number is %d.\n",n,dp[n]);
} return ;
}
POJ 2247 Humble Numbers的更多相关文章
- Poj 2247 Humble Numbers(求只能被2,3,5, 7 整除的数)
一.题目大意 本题要求写出前5482个仅能被2,3,5, 7 整除的数. 二.题解 这道题从本质上和Poj 1338 Ugly Numbers(数学推导)是一样的原理,只需要在原来的基础上加上7的运算 ...
- 递推(三):POJ中的三道递推例题POJ 1664、POJ 2247和POJ 1338
[例9]放苹果(POJ 1664) Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. In ...
- [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 ...
- 洛谷P2723 丑数 Humble Numbers
P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- js中如何优雅的写if判断
我们编写js代码时经常遇到复杂逻辑判断的情况,通常大家可以用if/else或者switch来实现多个条件判断,但这样会有个问题,随着逻辑复杂度的增加,代码中的if/else/switch会变得越来越臃 ...
- [同事转帖] .net core的服务器模式和工作站模式
发现自己的服务器上面的进程占用越来越厉害 所以就跟同事讨论了一下 性能组同事 说已经发现 并且给了一个 网址 这里转帖记录一下 避免以后找不到. .NET Core是一个开源通用的开发框架,具有跨平台 ...
- 关于linux上文件无法正确显示中文的情况解决
其实有遇到过多次,而且还有几次是css在预编译的时候,系统编码不对也会报错. 贴一个写的还不错的文章:http://www.360doc.com/content/11/0728/09/7102324_ ...
- delphi获取一个窗口的所有子窗口(包括嵌套)
unit Unit1; interface usesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...
- python之pygal:掷一个骰子统计次数并以直方图形式显示
源码如下: # pygal包:生成可缩放的矢量图形文件,可自适应不同尺寸的屏幕显示 # 安装:python -m pip intall pygal-2.4.0-py2.py3-none-any.whl ...
- JUC-Condition线程通信
1,Codition接口描述了可能会与锁有关联的条件变量.这些变量在用法上与使用Object.wait访问的隐式监视器类似. 但提供了更强大的功能,需要指出的是,单个lock可能与多个conditio ...
- ansible系列5-开启加速 Ansible 执行速度的功能
SSH pipelining 是一个加速 Ansible 执行速度的简单方法.ssh pipelining 默认是关闭,之所以默认关闭是为了兼容不同的 sudo 配置,主要是 requiretty 选 ...
- Spring JDBC 数据访问
Spring JDBC是Spring所提供的持久层技术,它的主要目标是降低使用JDBC API的门槛,以一种更直接,更简介,更简单的方式使用JDBC API, 在Spring JDBC里,仅需做那些与 ...
- xslt格式化日期的方法
数据:<PK_SEND_DATE>2007-9-28 0:00:00</PK_SEND_DATE> 通过截取:<xsl:value-of select="sub ...
- 洛谷UVA12995 Farey Sequence(欧拉函数,线性筛)
洛谷题目传送门 分数其实就是一个幌子,实际上就是求互质数对的个数(除开一个特例\((1,1)\)).因为保证了\(a<b\),所以我们把要求的东西拆开看,不就是\(\sum_{i=2}^n\ph ...