問題一覧 > 通常問題

No.3631 Collatz conjecture

レベル : / AI推定難易度 : 140 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 70
作問者 : 👑 ssmbc2929_bartok / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 13413 / 自分の提出
問題文最終更新日: 2026-07-25 21:42:44
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 510 数学まみれコンテスト (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。