Repetition
Time limit2sMemory limit1024 MB
Starting from X, apply the mod-3 rule (add 1, double, or triple) and count steps until the value reaches at least N.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Two positive integers X and N are given.
Initially, the integer X is written on a blackboard.
JOI repeats the following operation.
Operation: Let x be the number currently on the blackboard. Compute the remainder r when x is divided by 3. Depending on the value of r, replace the number on the blackboard as follows.
- If
r=0, replace it withxplus 1. - If
r=1, replace it withxtimes 2. - If
r=2, replace it withxtimes 3.
Find the number of operations needed until the number on the blackboard is at least N.
Input
Input is given in the following format.
X
N
Output
Print the number of operations needed until the number on the blackboard is at least N.
Print only the answer. Do not print any other text, including prompts for input.
Constraints
1 ≤ X < N ≤ 100000.- All input values are integers.