题意  所有只能被2,3,5,7这4个素数整除的数称为Humble Number  输入n  输出第n个Humble Number

1是第一个humble number  对于一个Humble Number  a  有2*a,3*a,5*a,7*a都是Humble Number  可以以1为基数  依次展开即可得到一定范围内的Humble Number 用i,j,k,l分别记录 2,3,5,7分别乘到了第几个Humble Number  当前在计算第cnt个Humble Number  那么有  hum[cnt] = min ( hum[i] * 2, hum[j] * 3, hum[k] * 5, hum[l] * 7)   然后对应min的i或j或k或l就加1  当cnt到达了n  结果就出来了

#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 5843;
int hum[N], cnt, n;
int main()
{int i = 1, j = 1, k = 1, l = hum[1] = 1;for (cnt = 2; cnt < N; ++cnt){hum[cnt] = min ( min(hum[i] * 2, hum[j] * 3), min (hum[k] * 5, hum[l] * 7));if (hum[cnt] == hum[i] * 2) ++i;if (hum[cnt] == hum[j] * 3) ++j;if (hum[cnt] == hum[k] * 5) ++k;if (hum[cnt] == hum[l] * 7) ++l;}while (scanf ("%d", &n), n){printf ("The %d", n);if (n % 100 != 11 && n % 10 == 1) printf ("st ");else if (n % 100 != 12 && n % 10 == 2) printf ("nd ");else if (n % 100 != 13 && n % 10 == 3) printf ("rd ");else printf ("th ");printf ("humble number is %d.\n", hum[n]);}return 0;
}

Humble Numbers

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.

转载于:https://www.cnblogs.com/acvay/p/3947286.html

HDU 1058 Humble Numbers(DP,数)相关推荐

  1. (HDU)1058 --Humble Numbers( 丑数)

    题目链接:http://vjudge.net/problem/HDU-1058 这题有点难度,自己写了半天依旧TLE,参考了其他人的博客. http://blog.csdn.net/pythonfx/ ...

  2. hdu 1058 Humble Numbers

    状态转移方程:F(n)=min(F(i)*2,F(j)*3,F(k)*5,F(m)*7)  (n>i,j,k,m) 特别的:i,j,k,m 只有在本项被选中后才移动 题目还要注意的一点是输出问题 ...

  3. usaco ★Humble Numbers 丑数

    ★Humble Numbers 丑数 对于一给定的素数集合 S = {p1, p2, ..., pK}, 来考虑那些质因数全部属于 S 的数的集合.这个集合包括,p1, p1p2, p1p1, 和 p ...

  4. Humble Numbers(丑数) 超详解!

    给定一个素数集合 S = { p[1],p[2],...,p[k] },大于 1 且素因子都属于 S 的数我们成为丑数(Humble Numbers or Ugly Numbers),记第 n 大的丑 ...

  5. zoj1095 Humble Numbers(DP)

    /*  简单DP:每次将求得的值分别乘以2,3,4,7,然后利用插入排序插入到数据序列中    保证数据的递增序,最终到达结束状态. */ View Code 1 #include <iostr ...

  6. 【HDOJ】1058 Humble Numbers

    简单题,注意打表,以及输出格式.这里使用了可变参数. 1 #include <stdio.h> 2 3 #define MAXNUM 5845 4 #define ANS 20000000 ...

  7. HDU 1058(打表)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1058 Humble Numbers Time Limit: 2000/1000 MS (Java/O ...

  8. Humble Numbers (谦卑数 || 丑数)

    Humble Numbers 题目来源:https://vjudge.net/contest/278033#problem/B || http://acm.hdu.edu.cn/showproblem ...

  9. BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数(数位DP+恶心细节)

    BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec  Memory Limit: 64 MB Description 正如你所知 ...

  10. HDU 1492 The number of divisors(约数) about Humble Numbers(数论,简单约数)

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

最新文章

  1. Win10 15063 开始运行不保存历史记录原因和解决方法
  2. 网站微信登录授权 ASP.NET
  3. 安装kibana,X-pack和elasticsearch插件的全过程
  4. 1013 Battle Over Cities
  5. 利用学习率衰减找到最优结果(基于Iris数据集)
  6. TCP协议疑难杂症全景解析|硬核
  7. 技术虚拟化人才实在化--3月19日西安建筑科技大学讲座
  8. eclipse中anroid adk添加
  9. jvm系列(九):如何优化Java GC
  10. 找取照片上的25个特征点,并保存结果
  11. 文件压缩 Huffman编码 (java)
  12. G1垃圾收集器之对象分配过程
  13. 大数据之-Hadoop之HDFS_HDFS的内容介绍---大数据之hadoop工作笔记0047
  14. ASP.NET和ASP程序防止在IE中进行缓存
  15. cmd后台运行exe_了解运行命令的原理,为QQ制作运行命令启动
  16. 小米官网竖直导航栏html,手把手教你做小米商城顶部导航栏
  17. AR图书,看着很美其实有点坑
  18. vue使用echarts图表渲染异常本地正常,线上时有时无的渲染
  19. 恒指赵鑫:8.7恒指德指喊单记录与晚盘前瞻
  20. android6 存储卡异常,手机SD卡无法读取时,如何在手机上修复损坏的SD卡?

热门文章

  1. 以前做过一个光标代码的梦,貌似也是个预言梦
  2. NVIDIA显卡超过一定路数,性能急剧下跌
  3. 羿的后人证明上古历史不是神话
  4. 假疫苗事件,错在企业,责任在管理部门
  5. python判断中文函数_如何判断(或如何编写)一个没有副作用的python函数?
  6. db2 replace函数的用法_C++常用函数整理
  7. php 解析字符串编码方式 GB2312 UTF8
  8. 变量函数命令 - Hugarian , Camel Pascal
  9. 【转】APP推广什么是cpa,cps,cpm
  10. [Erlang 0074] Erlang 杂记 IV