同1338
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; #define maxn 6000 #define inf 0x3f3f3f3f long long f[maxn]; int pos[4], fac[4]; char* make(int a, char *st) { if (a % 10 == 1 && a % 100 != 11) strcpy(st, "st"); else if (a % 10 == 2 && a % 100 != 12) strcpy(st, "nd"); else if (a % 10 == 3 && a % 100 != 13) strcpy(st, "rd"); else strcpy(st, "th"); return st; } int main() { // freopen("t.txt", "r", stdin); f[1] = 1; pos[0] = pos[1] = pos[2] = pos[3] = 1; fac[0] = 2; fac[1] = 3; fac[2] = 5; fac[3] = 7; for (int i = 2; i <= 5842; i++) { f[i] = -1; for (int j = 0; j < 4; j++) if (f[pos[j]] * fac[j] < f[i] || f[i] == -1) f[i] = f[pos[j]] * fac[j]; for (int j = 0; j < 4; j++) if (f[pos[j]] * fac[j] <= f[i]) pos[j]++; } int n; char st[3]; while (scanf("%d", &n), n) printf("The %d%s humble number is %lld.\n", n, make(n, st), f[n]); return 0; }