http://acm.hdu.edu.cn/showproblem.php?pid=1058
题意:就是不断的用已知的a[i]乘以2,3,5,7这四个数求里面的最小值(但是要比已知的最后一个a[i]要大)
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[6000];
int main()
{
int n,i,p2,p3,p5,p7;
a[1] = 1;
i = p2 = p3 = p5 = p7 = 1;
while(a[i] <= 2000000000) //想通这个循环这题就懂了
{
i++;
if(i == 6000)
{
break;
}
a[i] = min(2*a[p2],min(3*a[p3],min(5*a[p5],7*a[p7])));
if(a[i] == 2*a[p2]) p2++;
if(a[i] == 3*a[p3]) p3++;
if(a[i] == 5*a[p5]) p5++;
if(a[i] == 7*a[p7]) p7++;
}
while(scanf("%d",&n)&&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;
}