1 //找到数如何算即可
2 #include<stdio.h>
3 int a[6000]={1};
4
5 void Humble_Numbers();
6 int minf(int,int,int,int);
7
8 int main()
9 {
10 Humble_Numbers();
11 int n;
12 while(~scanf("%d",&n) && n)
13 {
14 printf("The %d",n);
15 if(n%10==1 && n%100!=11)
16 printf("st");
17 else if(n%10==2 && n%100!=12)
18 printf("nd");
19 else if(n%10==3 && n%100!=13)
20 printf("rd");
21 else
22 printf("th");
23 printf(" humble number is %d.\n",a[n-1]);
24 }
25 }
26
27 void Humble_Numbers()
28 {
29 int i=1,f1=0,f2=0,f3=0,f4=0;
30 while(i<5842)
31 {
32 int t1=a[f1]*2,t2=a[f2]*3,t3=a[f3]*5,t4=a[f4]*7;
33 int t = minf(t1,t2,t3,t4);
34 if(t != a[i-1])
35 a[i++]=t;
36 if(t == t1)
37 ++f1;
38 else if(t == t2)
39 ++f2;
40 else if(t == t3)
41 ++f3;
42 else if(t == t4)
43 ++f4;
44 }
45 }
46
47 int minf(int a,int b,int c,int d)
48 {
49 int t = a;
50 if(t > b) t=b;
51 if(t > c) t=c;
52 if(t > d) t=d;
53 return t;
54 }