http://acm.hdu.edu.cn/showproblem.php?pid=1058
#include <queue>
#include <map>
#include <iostream>
#include <functional>
using namespace std;
#define MAXI 5843
priority_queue<__int64, vector<__int64>, greater<__int64> > Q;
__int64 hn[MAXI], l;
map<__int64, bool> exi;
void init()
{
__int64 tmp;
l = 1;
Q.push(1);
while (l < MAXI)
{
tmp = Q.top();
Q.pop();
if (exi[tmp]) continue;
exi[tmp] = 1;
hn[l++] = tmp;
Q.push(tmp * 2);
Q.push(tmp * 3);
Q.push(tmp * 5);
Q.push(tmp * 7);
}
}
int main()
{
int n;
init();
while (scanf("%d", &n), n)
{
printf("The %d", n);
if (n % 10 == 1 && n % 100 != 11) printf("st ");
else if (n % 10 == 2 && n % 100 != 12) printf("nd ");
else if (n % 10 == 3 && n % 100 != 13) printf("rd ");
else printf("th ");
printf("humble number is %I64d.\n", hn[n]);
}
return 0;
}