The 3n+1 Problem(求各位高手修改)

本文探讨了一个算法,用于生成从任意整数开始的一系列数字,通过奇偶判断进行运算,直到序列终止于1。对于给定的两个整数范围,计算并输出该范围内所有数字的最大循环长度。
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 ofn, terminating when n = 1. For example, the following sequence ofnumbers 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 willterminate at n = 1 for every integer n. Still, the conjecture holdsfor all integers up to at least 1, 000, 000.

For an input n, the cycle-length of n is the number of numbersgenerated up to and including the 1. In the example above, thecycle length of 22 is 16. Given any two numbers i and j, you are todetermine the maximum cycle length over all numbers between i andj, including both endpoints.

Input
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 than1,000,000 and greater than 0.

Output
For each pair of input integers i and j, output i, j in the sameorder in which they appeared in the input and then the maximumcycle length for integers between and including i and j. Thesethree numbers should be separated by one space, with all threenumbers on one line and with one line of output for each line ofinput.

Sample Input

1 10
100 200
201 210
900 1000

Sample Output

1 10 20
100 200 125
201 210 89
900 1000 174

#include<stdio.h>
int func(int n)
{
 
   intcount=1;
   while(n!=1)
     
      if(n%2==0)
         n=n/2;
      else
         n=n*3+1;
      count++;
    }
    returncount;
}
int main()
{
    inti,j,max,t;
    scanf("%d%d",&i,&j);
   max=func(i);
   for(t=i+1;t<=j;t++)
    {
      if(max<func(t))
         max=func(t);
    }
    printf("%d%d %d\n",i,j,max);

}

### 回答13n + 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. 科贝尔因为此问题,在他的研究中发展出了一个术语“随机行走的周期时间”,并在研究自然环境的变化中提出了该术语的应用。 虽然迄今为止,人们仍未找到一个能够证明猜想正确与否的方法,但大量众志成城的项目,以及各种讨论和探寻的努力,让人们在探索数学的过程中,不断拓展了对于科学、技术、人类文化的认识和思考。 ### 回答33n+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、付费专栏及课程。

余额充值