CPP
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
#include <iostream>
#include <map>
#include <vector>
#include <cstdint>
std::map<uint_fast64_t, uint_fast64_t>seq_len{};
uint_fast64_t max_num{0}, max_len{0};
uint_fast64_t get_length_of_sequence(uint_fast64_t);
int main() {
for(uint_fast64_t i = 1; i < 1000000; ++i) {
auto len = get_length_of_sequence(i);
if(len > max_len) {
max_len = len;
max_num = i;
}
}
std::cout << "longest path at " << max_num << " (" << max_len << ")" << std::endl;
return 0;
}
uint_fast64_t get_length_of_sequence(uint_fast64_t n) {
if(seq_len.count(n) == 1)
return seq_len.at(n);
std::vector<uint_fast64_t>seq{n};
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run