#include<stdio.h>
const int num = 5842;
const long maxNum = 2000000000 + 3;
long humbles[num];
int min(int a,int b,int c,int d)
{
int t1,t2;
t1 = (a<b)?a:b;
t2 = (c<d)?c:d;
return t1<t2 ?t1 :t2;
}
//如果一个正整数的素因子只包含 2,3,5,7四种 注意只包含
void solve()
{
int i;
int in1 = 0,in2 = 0,in3 = 0,in4 = 0;
long hum1 = 0 ,hum2 = 0,hum3 = 0,hum4 = 0;
humbles[0] = 1;
for(i = 1 ; i < num; i ++)
{
hum1 = 2 *humbles[in1];
hum2 = 3 *humbles[in2];
hum3 = 5 *humbles[in3];
hum4 = 7 *humbles[in4];
humbles[i] = min(hum1,hum2,hum3,hum4);
if(humbles[i] == hum1) in1 ++;
if(humbles[i] == hum2) in2 ++;
if(humbles[i] == hum3) in3 ++;
if(humbles[i] == hum4) in4 ++;
}
}
int main(int argc,char *argv[])
{
int n;
solve();
while(scanf("%d",&n),n)
{
printf("The %d",n);
if(n%100!=11&&n%10==1) printf("st ");
else if(n%100!=12&&n%10==2) printf("nd ");
else if(n%100!=13&&n%10==3) printf("rd ");
else printf("th ");
printf("humble number is %ld.\n",humbles[n-1]);
}
return 0;
}
posted on 2010-07-19 17:47
付翔 阅读(498)
评论(0) 编辑 收藏 引用 所属分类:
ACM 数据结构