#P11063. 【MX-X4-T3】「Jason-1」数对变换

【MX-X4-T3】「Jason-1」数对变换

Background

Original problem link: https://oier.team/problems/X4D.

Problem Description

For a pair of positive integers (x,y)(x, y), define one transformation as follows: choose one number aa, let the other number be bb, and at the same time choose a positive integer kak \leq a. Then divide aa by kk and take the floor, and multiply bb by kk.

Formally, for the pair (x,y)(x, y), you may perform the following two types of transformations:

  • Type 1: choose 1kx1 \le k \le x, set $(x,y) \gets (\lfloor \frac{x}{k} \rfloor, y \cdot k)$.
  • Type 2: choose 1ky1 \le k \le y, set $(x,y) \gets (x \cdot k, \lfloor \frac{y}{k} \rfloor)$.

Obviously, the resulting pair is still a pair of positive integers.

Given two pairs of positive integers (a,b)(a, b) and (c,d)(c, d), you need to perform no more than 65\bm{65} transformations to change (a,b)(a, b) into (c,d)(c, d), or report that there is no solution. Note: you do not need to minimize the number of transformations.

Note that the pair is ordered, i.e., if xyx \neq y, then (x,y)(y,x)(x,y) \neq (y,x).

This problem uses a custom checker to verify whether your answer is correct, so if there are multiple valid solutions, you only need to output any one of them.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, the number of test cases. For each test case:

  • One line with four positive integers a,b,c,da, b, c, d, representing the two pairs.

Output Format

For each test case:

  • If there is no solution,
    • output one line with the string -1.
  • Otherwise,
    • the first line contains a non-negative integer mm, the number of transformations you perform. You must ensure 0m65\bm{0 \le m \le 65}, but you do not need to minimize m\bm m.
    • The next mm lines: the ii-th line contains two integers op,k\mathit{op}, k, representing the ii-th transformation. Here op{1,2}\mathit{op} \in \{1, 2\} indicates the transformation type, and kk is the chosen kk in this transformation.

This problem uses a custom checker to verify whether your answer is correct, so if there are multiple valid solutions, you only need to output any one of them.

7
1 1 1 1
1 2 1 1
2 2 1 2
10 10 2 50
5 5 4 10
80 43 52 64
987654321 123456789 313814116 388538872

0
-1
3
1 2
2 3
1 2
1
1 5
-1
2
1 3
2 2
2
1 31415
2 9982

Hint

[Sample Explanation]

For test case 1, no operation is needed because initially a=ca = c and b=db = d.

For test case 2, it can be proven that there is no solution.

For test case 3, after the first transformation (a,b)=(1,4)(a,b)=(1,4), after the second transformation (a,b)=(3,1)(a,b)=(3,1), and after the third transformation (a,b)=(1,2)(a,b)=(1,2).

For test case 4, one transformation is enough to make a=ca = c and b=db = d.

For test case 5, it can be proven that there is no solution.

For test case 6, after the first transformation (a,b)=(26,129)(a,b)=(26,129), and after the second transformation (a,b)=(52,64)(a,b)=(52,64).

For test case 7, after the first transformation (a,b)=(31438,3878395026435)(a,b)=(31438,3878395026435), and after the second transformation (a,b)=(313814116,388538872)(a,b)=(313814116,388538872).

[Constraints]

This problem uses bundled testdata.

Let n=max(a,b,c,d)n=\max(a,b,c,d).

Subtask nn\le Special Property Score
1 66 None 77
2 10510^5 A 1111
3 C 1313
4 10610^6 B 2323
5 10910^9 C 1919
6 None 2727
  • Special Property A: guaranteed ac=db\dfrac{a}{c}=\dfrac{d}{b}.
  • Special Property B: guaranteed a=ba=b and c=dc=d.
  • Special Property C: guaranteed that a,b,c,da,b,c,d are generated independently and uniformly at random within the value range.

For 100%100\% of the testdata, 1T1041 \le T \le 10^4, 1a,b,c,d1091 \le a,b,c,d \le 10^9.

Translated by ChatGPT 5