CSES Problemset/Introductory Problems
Weird Algorithm
#1068Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude DesktopConsider an algorithm that takes as input a positive integer . If is even, the algorithm divides it by two, and if is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until is one. For example, the sequence for is as follows: Your task is to simulate the execution of the algorithm for a given value of .
Input
The only input line contains an integer .
Output
Print a line that contains all values of during the algorithm.
Constraints
Sample Test Cases (1)
Example 1ID: sample-1
Input
3
Expected Output
3 10 5 16 8 4 2 1
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 charsTest Bench
Input (stdin)
3
Expected Output
3 10 5 16 8 4 2 1