这道题有很多种做法,但是思路大都是一样的,代码有点类似于poj2591这道题。
题意:问因子只含有2,3,5,7的第k个数是什么?
#include<stdio.h>
int f[5843],n;
int i,j,k,l;
int Min(int a,int b,int c,int d)
{
int _min = a;
if(b<_min) _min = b;
if(c<_min) _min = c;
if(d<_min) _min = d;
if(a==_min) i++;
if(b==_min) j++;
if(c==_min) k++;
if(d==_min) l++;
return _min;
}
int main()
{
i=j=k=l=1;
f[1] = 1;
for(int t=2;t<=5842;t++)
f[t] = Min(2*f[i],3*f[j],5*f[k],7*f[l]);
while(scanf("%d",&n),n)
{
if(n%100==11||n%100==12||n%100==13)
printf("The %dth humble number is %d.\n",n,f[n]);
else if(n%10==1)
printf("The %dst humble number is %d.\n",n,f[n]);
else if(n%10==2)
printf("The %dnd humble number is %d.\n",n,f[n]);
else if(n%10==3)
printf("The %drd humble number is %d.\n",n,f[n]);
else
printf("The %dth humble number is %d.\n",n,f[n]);
}
return 0;
}