Under construction

Still being built. Things may change

Repetition

Time limit2sMemory limit1024 MB

Summary
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 with x plus 1.
  • If r=1, replace it with x times 2.
  • If r=2, replace it with x times 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.

Examples4

  1. Example 1

    Input
    2
    40
    
    Expected output
    4
    
  2. Example 2

    Input
    3
    4
    
    Expected output
    1
    
  3. Example 3

    Input
    20
    62
    
    Expected output
    3
    
  4. Example 4

    Input
    1
    100000
    
    Expected output
    19