#d2147. BFS练习1

BFS练习1

BFS Practice 1

Problem Description

You are given a number aa. Each step you may choose one of the following four operations:

  1. Add one to aa.
  2. Multiply aa by 22.
  3. Multiply aa by 33.
  4. Subtract one from aa.

Find the minimum number of steps to change aa into bb.

You need to answer qq queries, with targets b1,b2,…,bqb_1, b_2, \dots, b_q; output the minimum number of steps to change aa into b1,b2,…,bqb_1, b_2, \dots, b_q.

Input Format

The first line contains two integers a,qa, q.

The next line contains qq integers b1,…,bqb_1, \dots, b_q.

Output Format

Output qq numbers, the minimum number of steps to change aa into b1,b2,…,bqb_1, b_2, \dots, b_q respectively.

Sample Input

3 10
1 2 3 4 5 6 7 8 9 10

Sample Output

2 1 0 1 2 1 2 2 1 2

Constraints

For all data, 1≤a,q,bi≤1051\le a, q, b_i \le 10^5.