Problems in Computer Science are often classified as belonging to a certain classof problems (e.g.,
NP, Unsolvable, Recursive). In this problem you will be analyzing a propertyof an algorithm whose
classification isnot known for all possible inputs.
Consider the following algorithm:
1. input n
2. print n
3.if n = 1then STOP
4.if n is odd then n ←− 3n + 15.else n ←− n/26. GOTO 2
Given the input 22, the following sequence of numbers will be printed
221134175226134020105168421
It is conjectured thatthe algorithm above will terminate (when a 1is printed) for any integral input
value. Despite the simplicity ofthe algorithm, itis unknown whether this conjecture istrue. It has
been verified, however, for all integers n such that0 < n < 1, 000, 000 (and, in fact, for many more
numbers than this.)
Given an input n, itis possible to determine thenumberof numbers printed beforeand including
the1is printed. For a given n this is called the cycle-lengthof n. In the example above, the cycle
lengthof22is16.
For any two numbers i and j you are to determine the maximum cycle lengthover all numbers
betweenand including both 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 than10,000andgreater than0.
You should process all pairs of integers andfor each pair determine the maximum cycle lengthover
all integers betweenand including i and j.
You can assume that no operation overflows a 32-bit integer.
Output
For each pair of input integers i and j you should output i, j, andthe maximum cycle lengthfor
integers betweenand including i and j. These three numbers should be separated byat least one spacewith all three numbers on one line andwith one line of output for each line of input. The integers i
and j must appear inthe output inthe same order in which they appeared inthe input and should be
followed bythe maximum cycle length (onthe same line).
Sample Input
1101002002012109001000
Sample Output
11020100200125201210899001000174
3n+1 问题: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