-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva443Humble Numbers.cpp
More file actions
99 lines (73 loc) · 2.01 KB
/
uva443Humble Numbers.cpp
File metadata and controls
99 lines (73 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<bits/stdc++.h>
#define pb(n) push_back(n)
#define bug cout<<"bug";
#define all(c) c.begin(),c.end()
#define fr(i,n) for(i=0;i<n;i++)
#define sf(n) scanf("%d",&n)
#define mst(n) memset(n,0,sizeof(n))
#define nl printf("\n")
#define lli long long int
#define tr(container,it) \
for (auto it = container.begin(); it != container.end() ; ++it)
#define INF INT_MAX
#define mp(i,j) make_pair(i,j)
#define mstn(n) memset(n,-1,szeof(n))
#define infile freopen("in.txt","r",stdin)
#define outfile freopen("out.txt","w",stdout)
#define ull unsigned long long
#define V 1000001
#define sz 1005
#define mod 1000000007
using namespace std;
void getHumbleNumber(int *humble)
{
humble[1]=1;
int mul2=1,mul3=1,mul5=1,mul7=1;
int w,x,y,z;
for(int i=2; i<=5842; i++)
{
w = humble[mul2] * 2;
x = humble[mul3] * 3;
y = humble[mul5] * 5;
z = humble[mul7] * 7;
// cout<<w<<x<<y<<z<<endl;
humble[i] = min(min(x,y),min(w,z)); // no special order
if(humble[i]==w) mul2++;
if(humble[i]==x) mul3++;
if(humble[i]==y) mul5++;
if(humble[i]==z) mul7++;
// cout<<humble[i]<<endl;
}
}
int main()
{
infile;
outfile;
int humble[6000];
getHumbleNumber(humble);
int num;
while(sf(num) && num)
{
if((num/10)%10==1)
{
printf("The %dth humble number is %d.\n",num,humble[num]);
continue;
}
switch(num%10)
{
case 1:
printf("The %dst humble number is %d.",num,humble[num]);
break;
case 2:
printf("The %dnd humble number is %d.",num,humble[num]);
break;
case 3:
printf("The %drd humble number is %d.",num,humble[num]);
break;
default:
printf("The %dth humble number is %d.",num,humble[num]);
break;
}
nl;
}
}