Humble Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24194    Accepted Submission(s): 10596

Problem Description
A
number whose only prime factors are 2,3,5 or 7 is called a humble
number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18,
20, 21, 24, 25, 27, ... shows the first 20 humble numbers.

Write a program to find and print the nth element in this sequence

 
Input
The
input consists of one or more test cases. Each test case consists of
one integer n with 1 <= n <= 5842. Input is terminated by a value
of zero (0) for n.
 
Output
For
each test case, print one line saying "The nth humble number is
number.". Depending on the value of n, the correct suffix "st", "nd",
"rd", or "th" for the ordinal number nth has to be used like it is shown
in the sample 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.
 
Source
题意:
求第n个质因子只有2,3,5,7的数。
代码:
 //从1开始每个humble数依次乘以2,3,5,7,从小到大排列出来,可以简化为f[i]=min(2*f[a],3*f[b],5*f[c],7*f[d]),当然用麻烦的方法也能做。
//注意1,2,3,21,22,23,111,112,113英文单词后缀st,nd,rd;11,12,13,10011,10012,10013,这样的和其他的后缀为th.
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b,c,d;
long long f[];
long min(long A,long B,long C,long D)
{
long MIN=A;
if(B<MIN) MIN=B;
if(C<MIN) MIN=C;
if(D<MIN) MIN=D;
if(MIN==A) a++;
if(MIN==B) b++;
if(MIN==C) c++;
if(MIN==D) d++;
return MIN;
}
int main()
{
a=b=c=d=;
f[]=;
for(int i=;i<=;i++)
f[i]=min(*f[a],*f[b],*f[c],*f[d]);
while(scanf("%d",&n)&&n)
{
if(n%==&&n%!=)
printf("The %dst humble number is %lld.\n",n,f[n]);
else if(n%==&&n%!=)
printf("The %dnd humble number is %lld.\n",n,f[n]);
else if(n%==&&n%!=)
printf("The %drd humble number is %lld.\n",n,f[n]);
else printf("The %dth humble number is %lld.\n",n,f[n]);
}
return ;
}

HDU1058 DP的更多相关文章

  1. DP 60题 -3 HDU1058 Humble Numbers DP求状态数的老祖宗题目

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  2. hdu1058丑数(优先队列、暴力打表)

    hdu1058 题意:当一个数只有2.3.5.7这四种质因数时(也可以一种都没有或只有其中几种),这个数就是丑数,输出第 n 个丑数是多少: 其实并没有发现hdu把这道题放在 dp 专题里的意图,我的 ...

  3. DP录 (更新)

    补补弱项 全面发展.. 从最基础来 sdut1299最长上升子序 #include <iostream> #include<cstdio> #include<cstrin ...

  4. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  5. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  6. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  7. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  8. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  9. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

随机推荐

  1. Vijos P1459 车展 treap求任意区间中位数

    描述 遥控车是在是太漂亮了,韵韵的好朋友都想来参观,所以游乐园决定举办m次车展.车库里共有n辆车,从左到右依次编号为1,2,…,n,每辆车都有一个展台.刚开始每个展台都有一个唯一的高度h[i].主管已 ...

  2. 用JAXP的SAX方式解析XML文件

    简单用JAXP的SAX方式(事件驱动)解析XML文件: 文件(1.XML) <?xml version="1.0" encoding="UTF-8" st ...

  3. URL编码表%20Base64编码表%20HTTP消息含义

    URL编码表 backspace 8% A 41% a 61% § %A7 Õ %D5   tab 9% B 42% b 62% « %AB Ö %D6   linefeed %0A C 43% c ...

  4. Intel CPU MMX SSE SSE2/3/4指令集手册下载URL

    在线查看的网址: https://software.intel.com/sites/landingpage/IntrinsicsGuide/ Intel® 64 and IA-32 Architect ...

  5. poj3642 01背包

    http://poj.org/problem?id=3624 #include<iostream> #include<cstdio> #include<algorithm ...

  6. css3 总结01

    前缀 chrome: -webkit- safari: -webkit- firefox: -moz- ie: -ms- opera: -o- 书写的时候应该先用有前缀的样式,再用无前缀的样式 颜色 ...

  7. AngularJS html+DOM+ng-click事件

    ng-disabled 指令直接绑定应用程序数据到 HTML 的 disabled 属性. ng-show 指令用于设置应用部分是否可见. ng-show="true" 设置 HT ...

  8. Jenkins基础 - 常用配置操作

    1.修改jenkins的根目录,默认地在C:\Users\用户名\.jenkins下(win7) 或C:\Documents and Settings\用户名\.jenkins(xp) 修改步骤: 增 ...

  9. git 学习笔记6--remote & log

    git 学习笔记6--remote & log 创建SSH Keys ssh-keygen -t rsa -C "1050244110@qq.com" 本地关联远程 git ...

  10. DOM基础2

    插入元素 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...