|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 欧拉计划 于 2023-8-5 23:11 编辑
题目14:找出100万以下最长的考拉兹序列
Longest Collatz sequence
The following iterative sequence is defined for the set of positive integers:
n → n/2 (n is even)
n → 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence:
13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
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.
题目翻译:
以下迭代序列定义在整数集合上:
- n → n/2 (当 n 是偶数时)
- n → 3n + 1 (当 n 是奇数时)
应用以上规则,并且以数字 13 开始,我们得到以下序列:
13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
可以看出这个以 13 开始以 1 结束的序列包含 10 个项。
虽然还没有被证明(考拉兹猜想),但是人们认为在这个规则下,以任何数字开始都会以 1 结束。
以哪个不超过 100 万的数字开始,能给得到最长的序列?
注意: 一旦序列开始之后,也就是从第二项开始,项是可以超过 100 万的。
视频讲解:
思路解析及源码参考(C & Python):
|
|