Take any number n. If n is even, divide it by 2, if n is odd, multiply it by 3 and add 1. Repeat the process indefinitely, and you'll eventually reach 1.
A Collatz sequence is the sequence of number generated from a specific
Boilerplate code is provided for Java. For other languages, read in the numbers from the standard input in the following format:
- The input starts with N, the number of cases.
- N lines follow, which each contains 1 integer.
Print out the correct numbers for each case on its own line.
Click on "View Raw I/O" below to view sample input and output.