The 坑题3n+1problem (python)

题目

Consider the following algorithm to generate a sequence of numbers. Start with an integer n. If n is even, divide by 2. If n is odd, multiply by 3 and add 1. Repeat this process with the new value of n, terminating when n = 1. For example, the following sequence of numbers will be generated for n = 22: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured (but not yet proven) that this algorithm will terminate at n = 1 for every integer n. Still, the conjecture holds for all integers up to at least 1, 000, 000. For an input n, the cycle-length of n is the number of numbers generated up to and including the 1. In the example above, the cycle length of 22 is 16. Given any two numbers i and j, you are to determine the maximum cycle length over all numbers between i and j, including both endpoints.
输入
The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0.
输出
For each pair of input integers i and j, output i, j in the same order in which they appeared in the input and then the maximum cycle length for integers between and including i and j. These three numbers should be separated by one space, with all three numb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 3n + 1问,也称为Collatz猜想,是一个数学问,它涉及到一个简单的算法,即对于任何正整数n,如果n是偶数,则将其除以2,否则将其乘以3再加1。这个算法会一直重复执行,直到n等于1为止。虽然这个算法看起来很简单,但至今没有人能够证明对于所有正整数n都能够最终收敛到1。这个问一直是数学界的一个谜,吸引了许多数学家的关注和研究。 ### 回答2: “3n+1问”也称为“Collatz猜想”,是解决数学领域中的一项经典问。这个问是对于每个正整数n,按照以下规则不断进行计算: (1) 如果n为奇数,计算3n +1; (2) 如果n为偶数,计算n/2; (3) 重复以上过程,直到n等于1为止。 猜想:无论初始值n是多少,经过有限次计算后一定会得到1。 在过去几十年中,无数数学家尝试用各种方法解决这个问,但目前仍未找到证据切实有效的方法来证明猜想的正确性。 为此,勒内·斯塔迪在2005年为完全确定“3n+1问”而创建了数字时限计划 ,该计划采用自由计算和验证方法,依赖众多志愿者的合作来解决这个难。 事实上,这个问并不仅仅只涉及到数学领域,它也有着重要的意义和应用价值。例如,可以通过优化算法来提高计算机的效率,甚至有人认为它与宇宙的本质有关。埃尔顿·M. 科贝尔因为此问,在他的研究中发展出了一个术语“随机行走的周期时间”,并在研究自然环境的变化中提出了该术语的应用。 虽然迄今为止,人们仍未找到一个能够证明猜想正确与否的方法,但大量众志成城的项目,以及各种讨论和探寻的努力,让人们在探索数学的过程中,不断拓展了对于科学、技术、人类文化的认识和思考。 ### 回答3: 3n+1问The 3n+1 problem),也叫做Collatz猜想,是指对于所有正整数n,按照如下规则进行递归操作。如果n是偶数,则把它除以2得到n/2;如果n是奇数,则把它乘以3再加1得到3n+1。按照这样的规则反复操作,最终可以得到一个数列1,4,2,1,4,2,1……其中1是最终结果,也是所有数字都会到达的终点。 尽管3n+1问规则很简单,但它一直是一个困扰数学家的难。目前还没有人能够证明这个所有数字最终都可以到达1的规律,也没有人能够找到一个能够对所有数字进行快速计算的算法。因此,这个问吸引了众多数学家和计算机科学家的关注,成为了一个经典的数学难。 3n+1问的研究不仅仅是理论的,也具有实际应用价值。例如,在计算机设计中,3n+1问可以用于测试计算机处理器的运算能力和稳定性。实际上,世界上许多大型计算机系统都会对3n+1问进行测试。 总之,3n+1问是一个经典而复杂的数学难,尽管它至今没有被完全证明,但是我们仍然可以通过研究和计算来探究这个问,不断拓展我们对数论和计算机科学的认识和理解。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值