-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP443.cpp
57 lines (52 loc) · 976 Bytes
/
P443.cpp
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
#include <iostream>
#include <set>
typedef unsigned long long ul;
typedef std::set<ul> set;
#define LEN 5842
void printEnd(ul n) {
if((n % 100 == 11)||(n % 100 == 12)||(n % 100 == 13)) {
std::cout << "th";
return;
}
switch(n%10) {
case 1:
std::cout << "st";
break;
case 2:
std::cout << "nd";
break;
case 3:
std::cout << "rd";
break;
default:
std::cout << "th";
break;
}
}
int main() {
int multipliers[4] = {2,3,5,7};
ul a[LEN];
int idx = 0;
set s;
for(int i = 1; i <= 10; ++i)
s.insert(i);
while(idx < LEN) {
ul min = *s.begin();
s.erase(min);
a[idx++] = min;
for(int i = 0; i < 4; ++i) {
ul mult = multipliers[i]*min;
if(s.find(mult) == s.end())
s.insert(mult);
}
}
int N;
while(true) {
std::cin >> N;
if(N == 0)
return 0;
std::cout << "The " << N;
printEnd(N);
std::cout << " humble number is " << a[N-1] << "." << std::endl;
}
}