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;
}

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

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

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

  2. A. Johny Likes Numbers(有坑的水题)

    题目如下: AC代码如下: #include<iostream> using namespace std; int main() {long long n, k;cin >> ...

  3. HDU2521 反素数【因子数量+打表+水题】

    反素数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  4. Codeforces 742A Arpa’s hard exam and Mehrdad’s naive cheat 打表+水题

    A. Arpa's hard exam and Mehrdad's naive cheat time limit per test 1 second memory limit per test 256 ...

  5. P4588 [TJOI2018]数学计算(线段树维护区间乘和单点修改)

    P4588 [TJOI2018]数学计算 刚看到这题根本每想到用线段树,直接每次记录计算结果然后找到要除的数字就好了呗 但是!你会注意到,如果连续乘很多很多次,然后再除的话,如果不取模会爆 long ...

  6. NUC1003 Hangover【数学计算+水题】

    Hangover 时间限制: 1000ms 内存限制: 65536KB 问题描述 How far can you make a stack of cards overhang a table? If ...

  7. NUC1011 Financial Management【数学计算+水题】

    Financial Management 时间限制: 1000ms 内存限制: 10000KB 问题描述 Larry graduated this year and finally has a job ...

  8. 【HDU - 5585】Numbers (水题,数学,数论)

    题干: There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise ...

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

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

最新文章

  1. react中使用构建缓存_如何在React中构建热图
  2. dev应用程序在其他电脑不能运行
  3. 2)JS动态生成HTML元素的爬取
  4. linux 挂载u盘区别不到,linux系统下为什么不能挂载U盘
  5. ASN.1 Editor
  6. 微信小程序多选取值判断显示内容
  7. mysql导入数据库某张表_MSSQLServer2005 导出导入数据库中某张表的数据
  8. ClassLoader.getResourceAsStream(name);获取配置文件的方法
  9. io_uring vs epoll ,谁在网络编程领域更胜一筹?
  10. .net mysql 类库_(精华)2020年6月27日 C#类库 MySqlHelper(Ado.net数据库封装)
  11. mac 10.12.6 Fiddler的安装
  12. 以命令行的方式运行activity
  13. opencv 实现图像时钟
  14. 用极大似然法估计因子载荷矩阵_spss教程:因子分析
  15. 《深入浅出WPF》——模板学习
  16. ignore的音标_单词ignore的音标_词典解释_翻译_相关例句_一直查
  17. word转PDF图片失真
  18. 微信报修小程序源码(近期维护V3.1.0)
  19. 信贷风控报表常用指标解读(一)
  20. linux自动关机取消命令,linux关机命令【使用思路】

热门文章

  1. 深入理解Unity刚体(Rigidbody)、碰撞器(Collider)、触发器(Trigger)
  2. [Serializable]在C#中的作用——实现.NET对象序列化
  3. mysql.servet复制到哪_Mysql复制及代理
  4. 5.3 同步操作和强制排序
  5. js打印服务器文件,用Electron / Node.js编写的打印服务器
  6. Hadoop的安装配置
  7. Linux下安装mysql(CentOS7)
  8. 登陆界面网页代码_Opera Touch移动浏览器登陆iPad 并引入隐私浏览模式
  9. 三维重建——使用colmap进行重建
  10. ip=request.servervariables(Remote_Addr)获得ip显示::1