Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Introductory Problems

Weird Algorithm

#1068
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

Consider an algorithm that takes as input a positive integer nn. If nn is even, the algorithm divides it by two, and if nn is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until nn is one. For example, the sequence for n=3n=3 is as follows: 3→10→5→16→8→4→2→13 \rightarrow 10 \rightarrow 5 \rightarrow 16 \rightarrow 8 \rightarrow 4 \rightarrow 2 \rightarrow 1 Your task is to simulate the execution of the algorithm for a given value of nn.

Input

The only input line contains an integer nn.

Output

Print a line that contains all values of nn during the algorithm.

Constraints
  • 1≤n≤1061 \le n \le 10^6
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 chars
Test Bench
Download .zip
Input (stdin)
3
Expected Output
3 10 5 16 8 4 2 1