# Problem 14 Longest Collatz sequence

The following iterative sequence is defined for the set of positive integers:

$$\large n\rightarrow \frac{n}{2}\ \left ( n\ is\ even \right ) ,n\rightarrow3n+1\ \left ( \ n\ is\ odd \right )$$

Using the rule above and starting with $13$, we generate the following sequence:

$$\large 13\rightarrow40\rightarrow20\rightarrow10\rightarrow5\rightarrow16\rightarrow8\rightarrow4\rightarrow2\rightarrow1$$

It can be seen that this sequence (starting at $13$ and finishing at 1) contains $10$ terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at $1$.
Which starting number, under one million, produces the longest chain?
NOTE: Once the chain starts the terms are allowed to go above one million.

# 问题 14 最长的考拉兹序列

$$\large n\rightarrow \frac{n}{2}\ \left ( n,是偶数 \right ) ,n\rightarrow3n+1\ \left ( n,是奇数 \right )$$

$$\large 13\rightarrow40\rightarrow20\rightarrow10\rightarrow5\rightarrow16\rightarrow8\rightarrow4\rightarrow2\rightarrow1$$

# 解题报告

## 考拉兹猜想

$$\large f\left ( n \right )=\left\{\begin{matrix}\frac{n}{2} \quad\quad\quad if \, n\equiv 0\\3n+1 \quad if \, n\equiv 1\end{matrix}\right.\left .\quad( mod \,\, 2 \right )$$

# 代码实现

• 递归算法
• 记忆化搜索算法优化
• longest Collatz sequence

Thank you for your support to Jason ~