PKU 2247 Humble Numbers 题意:由素数因子2,3,5,7组成得到的数(谦卑数)从小到大的序列。求该序列的第n个数。 分析:这题只要把那些谦卑数打表出来就可以了。 #include <stdio.h> #define MAX 5842 long long a[ MAX + 5]; long min(long x,long y) { if(x>y) return y ; else return x; } void printTable() { int i; int i1,i2,i3,i4; long t1,t2,t3,t4; a[0]=1; i1=0; i2=0; i3=0; i4=0; for(i=1;i<=MAX;i++) { t1=a[i1]*2; t2=a[i2]*3; t3=a[i3]*5; t4=a[i4]*7; a[i]=min(min(t1,t2),min(t3,t4)); if(t1==a[i]) i1++; if(t2==a[i]) i2++; if(t3==a[i]) i3++; if(t4==a[i]) i4++; //这里可不能用else,t1,t2,t3,t4可能相等 } } int main() { //freopen("input.txt","r",stdin); int n; printTable(); while(scanf("%d",&n)!=EOF && n) { int res = n % 10; int rs= n % 100; if(res==1&&rs!=11) printf("The %dst humble number is %ld./n",n,a[n-1]); else if(res==2&&rs!=12) printf("The %dnd humble number is %ld./n",n,a[n-1]); else if(res==3&&rs!=13) printf("The %drd humble number is %ld./n",n,a[n-1]); else printf("The %dth humble number is %ld./n",n,a[n-1]); } return 0; }