标签:
1 2 3 4 11 12 13 21 22 23 100 1000 5842 0
The 1st humble number is 1. The 2nd humble number is 2. The 3rd humble number is 3. The 4th humble number is 4. The 11th humble number is 12. The 12th humble number is 14. The 13th humble number is 15. The 21st humble number is 28. The 22nd humble number is 30. The 23rd humble number is 32. The 100th humble number is 450. The 1000th humble number is 385875. The 5842nd humble number is 2000000000.
#include<stdio.h> int dp[5900]; int min(int a,int b,int c,int d){ int t1,t2; t1=a>b?b:a; t2=c>d?d:c; return t1>t2?t2:t1; } void f(){ int f1,f2,f3,f4; f1=f2=f3=f4=1; dp[1]=1; for(int i=2;i<=5842;++i){ dp[i]=min(dp[f1]*2,dp[f2]*3,dp[f3]*5,dp[f4]*7); if(dp[i]==dp[f1]*2) f1++; if(dp[i]==dp[f2]*3) f2++; if(dp[i]==dp[f3]*5) f3++; if(dp[i]==dp[f4]*7) f4++; } } int main(){ f(); int n; 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 %d.\n",dp[n]); } return 0; }
好题,刚开始没找到思路,看看别人的代码才明白,真是水啊
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qq_18062811/article/details/47658137