hdu1058(找第n个数,其因子只含2,3,5,7)

题目意思:找第n个数,其因子只含2,3,5,7.

#include<stdio.h>

int main()

{

    int i,i1,i2,i3,i4,a[5850],min,min1;

    a[1]=1;i1=i2=i3=i4=1;

    for(i=2;i<=5842;i++)//打表算出拆分的最简因子只包含2,3,5,7四个数

    {

        min=a[i1]*2<a[i2]*3?a[i1]*2:a[i2]*3;//这些数从小到大排列

        min1=a[i3]*5<a[i4]*7?a[i3]*5:a[i4]*7;

        min=min<min1?min:min1;



        a[i]=min;

        if(min==a[i1]*2) i1++;

        if(min==a[i2]*3) i2++;

        if(min==a[i3]*5) i3++;

        if(min==a[i4]*7) i4++;

    }



    int n;

    while(scanf("%d",&n)==1&&n)

    {

        if(n%10==1&&n%100!=11)

        printf("The %dst humble number is %d.\n",n,a[n]);

       else if(n%10==2&&n%100!=12)

        printf("The %dnd humble number is %d.\n",n,a[n]);

       else if(n%10==3&&n%100!=13)

        printf("The %drd humble number is %d.\n",n,a[n]);

        else

        printf("The %dth humble number is %d.\n",n,a[n]);

    }

    return 0;

}


 

 

你可能感兴趣的:(HDU)