# ZOJ Problem Set - 1095（打表）

2017年02月24日 10点热度 0人点赞 0条评论

Humble Numbers

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 Specification

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 Specification

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: University of Ulm Local Contest 1996

#include
#include
using namespace std;
int main(){
int a[5845],p1,p2,p3,p4,k=1;
p1=p2=p3=p4=1;
a[k]=1;
while(k<5843){
a[++k]=min(min(a[p1]*2,a[p2]*3),min(a[p3]*5,a[p4]*7));
if(a[k]==a[p1]*2) p1++;
if(a[k]==a[p2]*3) p2++;
if(a[k]==a[p3]*5) p3++;
if(a[k]==a[p4]*7) p4++;
}
int n;
while(cin>>n&&n){
cout<<"The "<

 未经允许不得转载！ZOJ Problem Set - 1095（打表） 
 标签： 暂无 最后更新：2017年02月24日 
 update 纸上得来终觉浅， 绝知此事须躬行。 
 
 
 
 COPYRIGHT © 2020 52LEARN. ALL RIGHTS RESERVED.站长邮箱：1905822379@qq.com /* <![CDATA[ */ var kratos = {"site":"http:\/\/ai.52learn.online","directory":"http:\/\/ai.52learn.online\/wp-content\/themes\/Kratos-master","alipay":"http:\/\/ai.52learn.online\/wp-content\/uploads\/2020\/04\/QQ\u56fe\u724720200423225211.jpg","wechat":"http:\/\/ai.52learn.online\/wp-content\/uploads\/2020\/04\/QQ\u56fe\u724720200423225217.png","repeat":"\u60a8\u5df2\u7ecf\u8d5e\u8fc7\u4e86","thanks":"\u611f\u8c22\u60a8\u7684\u652f\u6301","donate":"\u6253\u8d4f\u4f5c\u8005","scan":"\u626b\u7801\u652f\u4ed8"}; /* ]]> */ /* <![CDATA[ */ var ajaxcomment = {"ajax_url":"http:\/\/ai.52learn.online\/wp-admin\/admin-ajax.php","order":"asc"}; /* ]]> */ /* <![CDATA[ */ var wshop_jsapi_params = {"ajax_url":"http:\/\/ai.52learn.online\/wp-admin\/admin-ajax.php","ajax_url_pay":"http:\/\/ai.52learn.online\/wp-admin\/admin-ajax.php?action=wshop_checkout_v2&tab=pay&wshop_checkout_v2=4e3962ac62&notice_str=5114507598&hash=281333df96f833d6182dbeb188097032","wp_login_url":"http:\/\/ai.52learn.online\/wp-login.php?redirect_to=%23location%23","payment_methods":[{"id":"wpopen_alipay","title":"\u652f\u4ed8\u5b9d","icon":"http:\/\/ai.52learn.online\/wp-content\/plugins\/wechat-shop\/assets\/image\/alipay.png"}],"msg_no_payment_method":"\u672a\u627e\u5230\u652f\u4ed8\u7f51\u5173\uff01","msg_err_500":"\u7cfb\u7edf\u9519\u8bef\uff0c\u8bf7\u7a0d\u5019\u91cd\u8bd5\uff01","msg_processing":"\u5904\u7406\u4e2d...","msg_add_to_cart_successfully":"\u4fdd\u5b58\u6210\u529f!","js_on_error":"alert"}; /* ]]> */ /* <![CDATA[ */ var ezTOC = {"smooth_scroll":"1","visibility_hide_by_default":"","width":"auto","scroll_offset":"30"}; /* ]]> */