枚举,貌似数据量挺大的,其实不大,就看最深层的tot加了多少次,就可估计出真正的规模
//枚举 #include <iostream> #include <stdio.h> #include <algorithm> #define ll long long using namespace std; const int maxn=2000000000; int num[10000]; int main() { ll i1,i2,i3,i4;//注意long long 因为虽然按理说是不会爆int,相乘这个过程可能会溢出 int tot=0; for(i1=1;i1<=maxn;i1*=2) { for(i2=1;i1*i2<=maxn;i2*=3) { for(i3=1;i1*i2*i3<=maxn;i3*=5) { for(i4=1;i1*i2*i3*i4<=maxn;i4*=7) num[tot++]=i1*i2*i3*i4; } } } sort(num,num+tot); int n; while(scanf("%d",&n)&&n) { if(n%100==11) printf("The %dth humble number is %d.\n",n,num[n-1]); else if(n%100==12) printf("The %dth humble number is %d.\n",n,num[n-1]); else if(n%100==13) printf("The %dth humble number is %d.\n",n,num[n-1]); else if(n%10==1) printf("The %dst humble number is %d.\n",n,num[n-1]); else if(n%10==2) printf("The %dnd humble number is %d.\n",n,num[n-1]); else if(n%10==3) printf("The %drd humble number is %d.\n",n,num[n-1]); else printf("The %dth humble number is %d.\n",n,num[n-1]); } return 0; }