- 1、本文档共3页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
The 3n + 1 problem--杭-电 1032
Problem Description
Problems in Computer Science are often classifiedas 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.
Consider the following algorithm:
input n
print n
if n = 1 then STOP
if n is odd then n - 3n + 1
else n - n / 2
GOTO 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
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.)
Given an input n, itis possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.
For any two numbers i and j you are to determine the max imum cycle length
over all numbers between i and j.
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 than 1,000,000 and greater than 0.
You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.
You can assume that no opperation overflows a 32-bit integer .
Output
For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
S
您可能关注的文档
最近下载
- 机械仿生狗设计说明书.doc
- 2025《西藏自治区建设工程计价定额》A房屋建筑与装饰工程.pdf
- 传送带同步运行功能使用说明书-北京迪基透科技有限公司.PDF
- 2025河北邯郸魏县选聘村级党务(村务)工作者490人笔试模拟试题参考答案详解.docx VIP
- 心脑血管疾病防治健康教育讲座课件PPT.ppt VIP
- 2025河北邯郸临漳县选聘农村党务(村务)工作者笔试模拟试题及答案解析.docx VIP
- 国开一网一 电子商务概论 实践任务(B2B电子商务网站调研报告).doc
- Siemens西门子工业SITRANS LR500 系列 (mA HART) SITRANS LR500 系列 (mA HART)使用手册.pdf
- 一种驻车空调和卡车启动共用锂电池模组.pdf VIP
- 电子商务学习记录.docx VIP
文档评论(0)