forked from jabbalaci/SpeedTests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (33 loc) · 642 Bytes
/
Copy pathmain.cpp
File metadata and controls
41 lines (33 loc) · 642 Bytes
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
#include <iostream>
#include <cmath>
constexpr auto MAX{int{440'000'000}};
int cache[10];
void set_cache()
{
cache[0] = 0;
for (int i = 1; i <= 9; ++i) {
cache[i] = pow(i, i);
}
}
auto is_munchausen(const int number) -> bool
{
auto total{0};
for (auto n{number}; n > 0; n /= 10)
{
auto digit{n % 10};
total += cache[digit];
if (total > number) {
return false;
}
}
return total == number;
}
auto main() -> int
{
set_cache();
for (int i = 0; i < MAX; ++i) {
if (is_munchausen(i)) {
std::cout << i << '\n';
}
}
}