POJ1207 The 3n+1 problem
传送门:POJ1207
关键词:水题、模拟
Description
Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.
计算机科学的问题通常被列为属于某一个特定类的问题(如NP、不可解、递归)。这个问题是请你分析算法的一个特性:算法的分类对所有可能的输入是未知的。
Consider the following algorithm:
考虑下述算法:
input n (输入n)
print n (打印n)
if n = 1 then STOP (如果n等于1,则停止)
if n is odd then n <-- 3n+1 (如果n是奇数,n=3n+1)
else n <-- n/2 (否则n=n/2)
GOTO 2 (跳转到第2步)
Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
给出输入“22”,则打印下述数字序列:22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.)
人们猜想,对于任何整数的输入值,上述算法将终止(当1被打印时)。尽管这一算法很简单,但还不清楚这一猜想是否是正确的。然而,目前已经验证,对所有的0 < n < 1,000,000的整数,该命题正确。
Given an input n, it is possible to determine the number of numbers printed before the 1 i