#P7161. [COCI 2020/2021 #2] Euklid

[COCI 2020/2021 #2] Euklid

Description

For positive integers a,ba, b, define R(a,b)R(a, b) as:

$\begin{cases}R(b,a)&a<b\\R\left(\left\lfloor\dfrac{a}{b}\right\rfloor,b\right)&1<b\leq a\\a&1=b\leq a\end{cases}$

Given positive integers g,hg, h, find positive integers a,ba, b such that gcd(a,b)=g\gcd(a,b)=g and R(a,b)=hR(a,b)=h.

Input Format

The first line contains an integer t (1t40)t\ (1\leq t\leq40), the number of test cases.
The next tt lines each contain two positive integers gi,hig_i, h_i.

Output Format

Output tt lines, each containing two positive integers ai,bia_i, b_i that satisfy the requirements.
Both aa and bb must not exceed 101810^{18}.
It can be proven that such a,ba, b always exist. If there are multiple solutions, output any one of them.

1
1 4
99 23
2
3 2
5 5
9 39
5 5

Hint

Sample Explanation #1

gcd(99,23)=1\gcd(99,23)=1, R(99,23)=4R(99,23)=4.

Constraints

For 100%100\% of the testdata, 1g200,0001 \leq g \leq 200,000, 2h200,0002 \leq h \leq 200,000.

Subtask #1 (44 pts): g=hg=h.
Subtask #2 (77 pts): h=2h=2.
Subtask #3 (77 pts): g=h2g=h^2.
Subtask #4 (1414 pts): g,h20g,h \leq 20.
Subtask #5 (3636 pts): g,h2000g,h \leq 2000.
Subtask #6 (3232 pts): no additional constraints.

Notes

Translated from Croatian Open Competition in Informatics 2020 ~ 2021 Round 2 C Euklid

Translated by ChatGPT 5