QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 1024 MB

#23938. Repetition

İstatistikler

Problem Statement

Positive integers $X$ and $N$ are given.

Initially, the integer $X$ is written on the blackboard.

JOI-kun repeats the following operation:

Operation: Let $x$ be the number currently written on the blackboard. Calculate the remainder when $x$ is divided by $3$, and let it be $r$. Depending on the value of $r$, rewrite the number written on the blackboard as follows:

  • When $r=0$, rewrite the number written on the blackboard with the number obtained by adding $1$ to $x$.
  • When $r=1$, rewrite the number written on the blackboard with the number obtained by multiplying $x$ by $2$.
  • When $r=2$, rewrite the number written on the blackboard with the number obtained by multiplying $x$ by $3$.

Find the number of operations required until the number written on the blackboard becomes $N$ or greater.

Constraints

  • $1 \le X < N \le 100\,000$.
  • All input values are integers.

Input

The input is given in the following format:

X
N

Output

Print the number of operations required until the number written on the blackboard becomes $N$ or greater.

Do not print anything other than the answer. (Do not print sentences prompting for input, etc.)

For the answer format, you may also refer to the practice problems and their sample solutions.

Sample 1

Sample Input 1

2
40

Sample Output 1

4
  • Initially, the number written on the blackboard is $2$.
  • In the $1$-st operation, the number $x$ written on the blackboard at the start of the operation is $2$. Since the remainder $r$ when $x$ is divided by $3$ is $2$, rewrite the number written on the blackboard to $6$, which is the number obtained by multiplying $x=2$ by $3$.
  • In the $2$-nd operation, the number $x$ written on the blackboard at the start of the operation is $6$. Since the remainder $r$ when $x$ is divided by $3$ is $0$, rewrite the number written on the blackboard to $7$, which is the number obtained by adding $1$ to $x=6$.
  • In the $3$-rd operation, the number $x$ written on the blackboard at the start of the operation is $7$. Since the remainder $r$ when $x$ is divided by $3$ is $1$, rewrite the number written on the blackboard to $14$, which is the number obtained by multiplying $x=7$ by $2$.
  • In the $4$-th operation, the number $x$ written on the blackboard at the start of the operation is $14$. Since the remainder $r$ when $x$ is divided by $3$ is $2$, rewrite the number written on the blackboard to $42$, which is the number obtained by multiplying $x=14$ by $3$.
  • Since the number written on the blackboard becomes $40$ or greater for the first time after $4$ operations, print $4$.

Sample 2

Sample Input 2

3
4

Sample Output 2

1

Sample 3

Sample Input 3

20
62

Sample Output 3

3

Sample 4

Sample Input 4

1
100000

Sample Output 4

19

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.