hdu(1058)初步数论

#include <stdio.h>
#include <string.h>
int min(int a,int b,int c,int d)
{
    int e=a<b?a:b;
    int f=c<d?c:d;
    int k=e<f?e:f;
    return k;
}
int main()
{
    int i1,i2,i3,i4;
    int f[6000],n;
    i1=i2=i3=i4=1;
    f[1]=1;
//处理技巧 for (int i=2;i<=5842;++i) { f[i]=min(f[i1]*2,f[i2]*3,f[i3]*5,f[i4]*7); if (f[i]==f[i1]*2) ++i1; if (f[i]==f[i2]*3) ++i2; if (f[i]==f[i3]*5) ++i3; if (f[i]==f[i4]*7) ++i4; } while(scanf("%d",&n),n) { 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("%d.\n",f[n]); } return 0; }

 

posted @ 2013-04-25 14:59  一线添  阅读(103)  评论(0编辑  收藏  举报