-
Notifications
You must be signed in to change notification settings - Fork 0
/
74.cpp
54 lines (51 loc) · 1.04 KB
/
74.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
#include <iostream>
#include <vector>
#include <unordered_map>
#include "combinatorics.h"
int next(int i, std::vector<int> &f) {
int ans = 0;
while (i != 0) {
ans += f[i % 10];
i /= 10;
}
return ans;
}
int main() {
constexpr int limit = 1'000'000;
std::vector<int> f(10);
for (int i = 0; i < 10; ++i) f[i] = factorial(i);
std::unordered_map<int, int> cache;
//169 → 363601 → 1454 → 169
//871 → 45361 → 871
//872 → 45362 → 872
cache[169] = 3;
cache[363601] = 3;
cache[1454] = 3;
cache[871] = 2;
cache[45361] = 2;
cache[872] = 2;
cache[45362] = 2;
for (int start = 1; start < limit; ++start) {
if (cache.find(start) != cache.end()) continue;
int len = 1;
int cur = start;
while (true) {
auto tmp = next(cur, f);
if (tmp == cur) {
cache[start] = len;
break;
} else if (cache.find(tmp) != cache.end()) {
len += cache[tmp];
cache[start] = len;
break;
}
cur = tmp;
++len;
}
}
int ans = 0;
for (auto &[a, b] : cache) {
if (b == 60) ++ans;
}
std::cout << ans << std::endl;
}