Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description (Write in Java) Consider the following algorithm. Input n Print n If n == 1 then STOP If n is odd then n =

Description (Write in Java)

Consider the following algorithm.

Input n

Print n

If n == 1 then STOP

If n is odd then n = 3*n + 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 (stops after printing 1) for any integer value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for very large integers. Given an input n, the number of numbers printed (including 1) is called the cycle-length of n. In the example above where n is 22, the cycle length is 16. For any two integers I and J, you shall determine the maximum cycle length and the minimum cycle length over all numbers between (and including) I and J.

Input

The first line of the input gives the number of cases, N. N test cases follow. For each test case there will be one line that contains a pair of integers I and J. All integers will be less that 10,000 and greater than 0.

Output

For each pair of input integers I and J you shall output one line that contains I, J, the minimum cycle length, and the maximum cycle length. The cycle lengths shall be computed for integers between and including I and J. The I and J output must be in the same order in which they appeared in the input. The exact format for each output line is shown in the sample output.

Sample Input

4 1 10 100 200 201 210 900 1000 

Sample Output

Range: 1...10 Min: Num: 1, Cycle: 1 Max: Num: 9, Cycle: 20 Range: 100...200 Min: Num: 128, Cycle: 8 Max: Num: 171, Cycle: 125 Range: 201...210 Min: Num: 208, Cycle: 14 Max: Num: 206, Cycle: 89 Range: 900...1000 Min: Num: 904, Cycle: 16 Max: Num: 937, Cycle: 174 

The following explains the first output line above.

The range of numbers is 1 to 10 -

Range: 1...10

The number 1 generates the minimum cycle for the range 1 to 10 and its cycle is 1 -

Min: Num: 1, Cycle: 1

The number 9 generates the maximum cycle for the range 1 to 10 and its cycle is 20 -

Max: Num: 9, Cycle: 20

Additional Information

You should use a Scanner to read the input values.

Do not prompt for input. The input will be there.

You should use System.out.println() to generate your output.

The output line has to match exactly.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions