No.2534 Collatz Sequence
タグ : / 解いたユーザー数 117
作問者 : 👑
srjywrdnprkt
Problem Statement
An integer $N$ is given as input.
For an integer $n$, we call the following series of operations $P(n)$:
- Set the value of the integer variable $n'$ to $n$. Proceed to the next step.
- If the value of $n'$ is $1$, proceed to step 4; otherwise, proceed to the next step.
- 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.
- 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もしくは右上の雲マークをクリックしてアカウントを作成してください。