# POJ 2247 && HDU 1058 Humble Numbers（数论）

Description

Input

Output

Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
Sample Output
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.
Solution

Code

#include<stdio.h>
#define min(x,y) x<y?x:y
int main()
{
int i,u2,u3,u5,u7,n;
long int ugly[6000];
ugly[1]=1;
u2=1;
u3=1;
u5=1;
u7=1;
for(i=2;i<6000;i++)
{
ugly[i]=min(ugly[u3]*3,ugly[u5]*5);
ugly[i]=min(ugly[i],ugly[u2]*2);
ugly[i]=min(ugly[i],ugly[u7]*7);
if(ugly[i]==ugly[u2]*2)
u2++;
if(ugly[i]==ugly[u3]*3)
u3++;
if(ugly[i]==ugly[u5]*5)
u5++;
if(ugly[i]==ugly[u7]*7)
u7++;
}
while(scanf("%d",&n)&&n)
{
if(n%100>10&&n%100<20)
printf("The %dth humble number is %d.\n",n,ugly[n]);
else if(n%10==1)
printf("The %dst humble number is %d.\n",n,ugly[n]);
else if(n%10==2)
printf("The %dnd humble number is %d.\n",n,ugly[n]);
else if(n%10==3)
printf("The %drd humble number is %d.\n",n,ugly[n]);
else
printf("The %dth humble number is %d.\n",n,ugly[n]);
}
}


#### HDU Humble Numbers （dp）

2015-06-14 22:22:34

#### poj 2247 Humble Numbers

2014-07-22 21:08:41

#### POJ 2247 Humble Numbers

2014-04-27 20:42:30

#### poj 2247 Humble Numbers

2013-10-28 16:14:57

#### POJ 2247（Humble Numbers）

2012-09-13 15:08:25

#### HDU 1058 &amp; POJ 2247 Humble Number

2013-04-10 21:02:09

#### Hdu 1058 — Humble Numbers

2014-07-21 15:51:44

#### HDU 1058 Humble Numbers

2016-08-29 17:17:40

#### HDU 1058 Humble Numbers

2013-09-05 21:17:30