QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#15180. Variable-base Rounding

統計

On Thursdays and Fridays, we often say that rounding is approximately equal to having a holiday.

However, Louis is curious whether it is possible to use a rounding method to turn any number into any other number. This way, she could consider any day to be approximately equal to her favorite holiday and be in a good mood every day. To this end, Louis defines an operation that takes the current number $N$, represents it in base $k$ as $N_{(k)}$, and then rounds it at the $i$-th position from the right, denoted as $f(k, i)$. Obviously, for integers, this operation is only meaningful when $1 < i$.

It is worth noting that the rounding in this operation is different from the rounding in everyday life. Formally, for the operation $f(k, p)$, the execution checks the digit $x$ at the $(p-1)$-th position from the right in $N_{(k)}$. When $x \le \lfloor \frac{k}{2} \rfloor$, it will "round down", otherwise it will "round up".

For example, when $N = 20$, the steps to execute the operation $f(8, 2)$ are as follows:

  1. Represent $20$ as $24_{(8)}$.
  2. Check the digit at the $1$-st position from the right: $4 \le \lfloor \frac{8}{2} \rfloor = 4$.
  3. "Round down" the number to $20_{(8)}$, so after the operation $N = 16$.

When $N = 21$, the steps to execute the operation $f(8, 2)$ are as follows:

  1. Represent $21$ as $25_{(8)}$.
  2. Check the digit at the $1$-st position from the right: $5 > \lfloor \frac{8}{2} \rfloor = 4$.
  3. "Round up" the number to $30_{(8)}$, so after the operation $N = 24$.

Now Louis wants to know, for two specific integers $x$ and $y$, a scheme to transform $x$ into $y$ using the provided operations. Since Louis is very eager to have a holiday, the scheme you provide must use no more than $55$ operations.

Input

The input consists of a single line containing two integers $x, y$ ($1 < x, y \le 10^9$).

Output

The first line outputs an integer $n$, representing the number of operations used.

Next, $n$ lines follow, each containing two integers $k_i, p_i$, representing that the $i$-th operation performed is $f(k_i, p_i)$.

For a test case, you are considered to have passed if and only if your output scheme satisfies $0 \le n \le 55$, $1 < k_i \le 10^9$, $1 < p_i \le \lfloor \log_{k_i} 10^9 \rfloor + 1$, and after performing all operations, $x$ becomes $y$, while ensuring that the number never exceeds $2 \times 10^9$ at any time.

Examples

Input 1

6 16

Output 1

2
3 3
16 2

Input 2

7 4

Output 2

1
2 3

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.