No.3631 Collatz conjecture
タグ : / 解いたユーザー数 70
作問者 : 👑
Problem Statement
Define a function $f(n)$ as follows.
$f(n) = \begin{cases} n/2 & (n \equiv 0 \pmod{2}) \\ 3n+1 & (n \not\equiv 0 \pmod{2}) \end{cases}$
Starting with a given positive integer $N$ as the initial value of $n$, repeat the operation "replace $n$ with $f(n)$".
Find the number of operations required, performing it $1$ or more times, until the value becomes $1$ for the first time.
However, if the value does not reach $1$ within $10^{100}$ operations, output infinity.
Constraints
- $1 \le N \le 3000$
- $N$ is an integer
Input
$N$
Output
Output the answer on $1$ line.
Print a newline at the end.
Sample
Sample 1
Input
5
Output
5
The value changes as $5 \to 16 \to 8 \to 4 \to 2 \to 1$, so the number of applications is $5$.
Sample 2
Input
10
Output
6
The value changes as $10 \to 5 \to 16 \to 8 \to 4 \to 2 \to 1$, so the number of applications is $6$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。