Problem Description
source:https://uva.onlinejudge.org/external/6/694.html
An algorithm given by Lothar Collatz produces sequences of integers, and is described as follows:
Step 1: Choose an arbitrary positive integer A as the first item in the sequence.
Step 2: If A = 1 then stop.
Step 3: If A is even, then replace A by A/2 and go to step 2.
Step 4: If A is odd, then replace A by 3 ∗ A + 1 and go to step 2.
It has been shown that this algorithm will always stop (in step 2) for initial values of A as large as 109 , but some values of A encountered in the sequence may exceed the size of an integer on many computers. In this problem we want to determine the length of the sequence that includes all values produced until either the algorithm stops (in step 2), or a value larger than some specified limit would be produced (in step 4).
source:https://uva.onlinejudge.org/external/6/694.html
An algorithm given by Lothar Collatz produces sequences of integers, and is described as follows:
Step 1: Choose an arbitrary positive integer A as the first item in the sequence.
Step 2: If A = 1 then stop.
Step 3: If A is even, then replace A by A/2 and go to step 2.
Step 4: If A is odd, then replace A by 3 ∗ A + 1 and go to step 2.
It has been shown that this algorithm will always stop (in step 2) for initial values of A as large as 109 , but some values of A encountered in the sequence may exceed the size of an integer on many computers. In this problem we want to determine the length of the sequence that includes all values produced until either the algorithm stops (in step 2), or a value larger than some specified limit would be produced (in step 4).