Humble Numbers

时间限制: 1000ms 内存限制: 65536KB

通过次数: 1总提交次数: 1

问题描述

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.

输入描述
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.

输出描述
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.

样例输入
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.

来源
{Ulm Local 1996}

问题分析:(略)

这个问题和《POJ2247 HDU1058 UVA443 ZOJ1095 Humble Numbers【数学计算+打表】》是同一个问题,代码拿过来用就AC了。

程序说明:参见参考链接。

参考链接:POJ2247 HDU1058 UVA443 ZOJ1095 Humble Numbers【数学计算+打表】

题记:程序做多了,不定哪天遇见似曾相识的。

AC的C++程序如下:

/* POJ2247 HDU1058 UVA443 ZOJ1095 Humble Numbers */#include <iostream>
#include <stdio.h>using namespace std;const int N = 5842;
int humble[N];void maketable(int n)
{int i2, i3, i5, i7;int h2, h3, h5, h7;humble[0] = 1;i2 = i3 = i5 = i7 = 0;h2 = humble[i2] * 2;h3 = humble[i3] * 3;h5 = humble[i5] * 5;h7 = humble[i7] * 7;for(int i=1; i<n; i++) {humble[i] = min(min(h2, h3), min(h5, h7));if(h2 == humble[i]) {h2 = humble[++i2] * 2;}if(h3 == humble[i]) {h3 = humble[++i3] * 3;}if(h5 == humble[i]) {h5 = humble[++i5] * 5;}if(h7 == humble[i]) {h7 = humble[++i7] * 7;}}
}int main()
{maketable(N);int n;while(cin >> n && n) {if(n%10 == 1 && n % 100 != 11)printf("The %dst humble number is ", n);else if(n%10 == 2 && n % 100 != 12)printf("The %dnd humble number is ", n);else if(n%10 == 3 && n % 100 != 13)printf("The %drd humble number is ", n);elseprintf("The %dth humble number is ", n);printf("%d.\n", humble[n - 1]);}return 0;
}

转载于:https://www.cnblogs.com/tigerisland/p/7563676.html

NUC1077 Humble Numbers【数学计算+打表】相关推荐

  1. NUC1077 Humble Numbers【数学计算+打表+水题】

    Humble Numbers 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 A number whose only prime factors are ...

  2. 计算机表格计算总积分,Excel函数教程: 根据条件计算成绩表-excel技巧-电脑技巧收藏家...

    Excel函数教程: 根据条件计算成绩表 (三)根据条件计算值 在了解了IF函数的使用方法后,我们再来看看与之类似的Excel提供的可根据某一条件来分析数据的其他函数.例如,如果要计算单元格区域中某个 ...

  3. poj 2247 Humble Numbers

    Humble Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9453   Accepted: 4440 题目 ...

  4. 用计算机计算的手抄报内容,关于数学计算手抄报

    开办手抄报对学生是一项综合性很强的实践活动.下面是学习啦小编为大家带来的关于数学计算手抄报,希望大家喜欢. 数学计算手抄报的图片欣赏 数学计算手抄报图一 数学计算手抄报图二 数学计算手抄报图三 数学计 ...

  5. HDU1492 The number of divisors(约数) about Humble Numbers【约数】

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

  6. 《趣题学算法》—第1章1.2节简单的数学计算

    本节书摘来自异步社区<趣题学算法>一书中的第1章1.2节简单的数学计算,作者徐子珊,更多章节内容可以访问云栖社区"异步社区"公众号查看. 1.2 简单的数学计算 以上那 ...

  7. 用计算机器提高正确率,如何提高数学计算题的正确率

    计算题是小学数学的一个重要的题型,对于计算题如何提高计算题的正确率,减少不必要的额错误呢?下面是小编整理的如何提高数学计算题的正确率,希望大家喜欢. 第一.要对计算引起足够的重视 很多同学总以为计算题 ...

  8. C/C++数学计算库

    c/c++数学计算库,他们基本上都是开源的,你完全不必担心版权问题,他们都是一些自由软件,你要做的仅仅是仔细阅读他们的授权协议确保不要滥用就可以了: 计算几何算法库 CGAL CGAL ,计算几何算法 ...

  9. Shell数学计算(算术运算,加减乘除运算)

    声明: 本篇博客的学习途径主要为以下网站和课堂讲解,发博客目的仅为学习使用,在该博客的基础上做了一定程序的简略和修改. 参考博客 : 原文链接:http://c.biancheng.net/shell ...

最新文章

  1. MySQL主从复制原理图
  2. SQL Server备份的三个恢复模型
  3. 借助LDA主题分析的短文本相似性计算 - 综述帖
  4. FM算法python实现
  5. jzoj3382-七夕祭【贪心,中位数】
  6. 将25k行C#转换为Java的经验教训
  7. css 关闭按钮实现,CSS做的关闭按钮动效
  8. 打印速度快点的打印机_瞒着领导偷偷给你们发两台打印机
  9. java list 获取索引_java – 获取arrayList中元素的索引
  10. 2-2:C++快速入门之输入和输出
  11. MyBatis Invalid bound statement (not found)问题 -- 记一次与空气的斗智斗勇
  12. python文件写入_python读写不同编码txt文件
  13. 安装sql2000提示html,安装sql2000数据库提示:command line option syntax error
  14. KeilC51基本关键字
  15. 送给梨花仙子国的礼物
  16. JS放大镜小功能功能之原理详细解析
  17. 电商后台设计详细讲解
  18. DirectX和OPenGL 与 UE4 U3D的关系是什么?
  19. html onload 写法,HTML onload用法及代码示例
  20. python基础3---循环和字符串列表

热门文章

  1. 蓝桥杯 ADV-205 算法提高 拿糖果 java版
  2. 已知后序与中序输出前序(先序)
  3. Eclipse 安装 Fatjar.jar失败的解决方法
  4. python数组写入txt
  5. 新手常见的python报错及解决方案
  6. mysql 查看索引
  7. Firefox 67不能勾选“以后自动采用相同的动作处理此类文件”解决方案
  8. Educational Codeforces Round 52E(构造,快速幂)
  9. BZOJ2535: [Noi2010]Plane 航空管制2(拓扑排序 贪心)
  10. golang | 空结构体struct{}的用法