# acm_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. <br><br>Write a program to find and print the nth element in this sequence<br>

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.<br>

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.<br>

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 <string>
#include<stdio.h>
#include<vector>
#include<cmath>
using namespace std;
int inline min(int a,int b)
{
return a<b?a:b;
}
int main(){
int n = 5842, m;
char s[4][3]={"th","st","nd","rd"};
vector<int> v;
int a = 0, b = 0, c = 0, d = 0;
v.push_back(1);
while(--n){
int r2 = v[a] * 2;
int r3 = v[b] * 3;
int r5 = v[c] * 5;
int r7 = v[d] * 7;
m = min(r2, r3);
m = min(m, r5);
m = min(m, r7);
v.push_back(m);
if(r2 == m)
a+=1;
if(r3 == m)
b+=1;
if(r5 == m)
c+=1;
if(r7 == m)
d+=1;
}
while(cin>>n&&n!=0)
{
string cc=(n % 10 < 4 && n % 100 != 11 && n % 100 != 12 && n % 100 != 13)?s[n % 10]:"th";
cout<<"The "<<n<<cc<<" humble number is "<<v[n - 1]<<"."<<endl;
}
return 0;
}

• 本文已收录于以下专栏：

## 1120. Friend Numbers (20)[字符串处理]

1. 原题：https://www.patest.cn/contests/pat-a-practise/1120 2. 思路： 题意：字符处理题。求出每个数字的和，然后从小到大输出。 思路： ...
• shepherd2010
• 2017年05月23日 20:59
• 210

## Uva 10539 Almost Prime Numbers

• chai_jing
• 2016年09月19日 18:09
• 151

## Python学习笔记 —— 数字类型【Numbers】及常用方法

Tips: 在Python中数据类型不允许改变的，如果改变了，则会重新分配内存空间。 pi: 数字常量pi(圆周率) e:自然常数 Numbers支持四种不同的数值类型：整型...
• linfengwenyou
• 2016年06月06日 15:05
• 872

## UVA 10539 Almost Prime Numbers(唯一分解定理)

• qwe585p
• 2015年11月01日 21:37
• 388

## UVA 10539 - Almost Prime Numbers(数论)

UVA 10539 - Almost Prime Numbers 题目链接 题意：给定一个区间，求这个区间中的Almost prime number，Almost prime number...
• u011217342
• 2014年06月24日 01:02
• 1466

## Sum of Distinct Numbers(求组成N的不同个数和)

Sum of Distinct Numbers Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB ...
• modiz
• 2014年10月13日 08:53
• 1074

## URAL 1586 Threeprime Numbers （数位DP）

• xuechelingxiao
• 2014年08月18日 12:25
• 816

C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes...
• liuke19950717
• 2016年07月18日 16:53
• 343

## 经典 数学问题 Fibonacci Numbers

Fibonacci Numbers Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other...
• hpugym
• 2015年02月12日 16:04
• 649

## HDU Humble Numbers （dp）

Humble Numbers Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot...
• zp___waj
• 2015年06月14日 22:22
• 996

举报原因： 您举报文章：acm_Humble Numbers 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)