打表。输出的时候注意th,st,nd,rd。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; long long h[6000]; int cnt; void f() { cnt=0; for(long long a=1;a<=2000000000;a=a*2) { for(long long b=1;a*b<=2000000000;b=b*3) { for(long long c=1;a*b*c<=2000000000;c=c*5) { for(long long d=1;a*b*c*d<=2000000000;d=d*7) { cnt++; h[cnt]=a*b*c*d; } } } } sort(h+1,h+1+cnt); } int main() { f(); int n; while(~scanf("%d",&n)) { if(n==0) break; if(n%10==1&&n%100!=11) printf("The %dst humble number is ",n); else if(n%10==2&&n%100!=12) printf("The %dnd humble number is ",n); else if(n%10==3&&n%100!=13) printf("The %drd humble number is ",n); else printf("The %dth humble number is ",n); printf("%lld. ",h[n]); } return 0; }