問題一覧 > 教育的問題

No.2534 Collatz Sequence

レベル : / AI推定難易度 : 275 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 117
作問者 : 👑 p-adic / テスター : srjywrdnprkt hiro1729
お気に入りにしたユーザー ProblemId : 9095 / 自分の提出
問題文最終更新日: 2023-07-21 23:47:30
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 412 (順位表) の他の問題:

Problem Statement

An integer $N$ is given as input.

 

For an integer $n$, we call the following series of operations $P(n)$:

  1. Set the value of the integer variable $n'$ to $n$. Proceed to the next step.
  2. If the value of $n'$ is $1$, proceed to step 4; otherwise, proceed to the next step.
  3. If the value of $n'$ is divisible by $2$, replace the value of $n'$ with the value of $2^{-1} n'$; otherwise, replace the value of $n'$ with the value of $3n' + 1$. Return to step 2.
  4. Terminate the operation.

By definition, step 4 is executed at most $1$ time in $P(n)$. We say that $P(n)$ halts if step 4 is executed in $P(n)$.

If $P(n)$ halts, the total number of times steps 1,2,3 have been executed up to that point is called the halting step count of $P(n)$.

$P(n)$ halts within $50$ steps means that $P(n)$ halts and the halting step count of $P(n)$ is at most $50$.

 

Determine whether $P(N)$ halts within $50$ steps, and if it halts within $50$ steps, find its halting step count.

Input

The input is given from standard input in the following format:
$N$

Constraints

The input satisfies the following constraints:

  • $N$ is an integer satisfying $-1000 \leq N \leq 1000$

Output

If $P(N)$ halts within $50$ steps, print Yes on line $1$ and its halting step count on line $2$.

If $P(N)$ does not halt, print No.

Print a newline at the end.

Sample

Sample 1
Input
0
Output
No

Writing out the step numbers and the value of the integer variable $n'$ after each step in the operation $P(0)$, we get

手順1: $n' = 0$
手順2: $n' = 0$
手順3: $n' = 0$
手順2: $n' = 0$
手順3: $n' = 0$
手順2: $n' = 0$
手順3: $n' = 0$
手順2: $n' = 0$
手順3: $n' = 0$
手順2: $n' = 0$
手順3: $n' = 0$
$\vdots$

and $P(0)$ does not halt. In particular, $P(0)$ does not halt within $50$ steps.

Sample 2
Input
1
Output
Yes
2

Writing out the step numbers and the value of the integer variable $n'$ after each step in the operation $P(1)$, we get

手順1: $n' = 1$
手順2: $n' = 1$
手順4: $n' = 1$

and $P(1)$ halts with a halting step count of $2$. In particular, $P(1)$ halts within $50$ steps.

Sample 3
Input
2
Output
Yes
4

Writing out the step numbers and the value of the integer variable $n'$ after each step in the operation $P(2)$, we get

手順1: $n' = 2$
手順2: $n' = 2$
手順3: $n' = 1$
手順2: $n' = 1$
手順4: $n' = 1$

and $P(2)$ halts with a halting step count of $4$. In particular, $P(1)$ halts within $50$ steps.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。