#P7161. Find a Pair of Integers with Given GCD and Recurrence Function Value
Find a Pair of Integers with Given GCD and Recurrence Function Value
Find a Pair of Integers with Given GCD and Recurrence Function Value
For any two positive integers \(a\) and \(b\), we define a recursive function \(R(a,b)\) as follows:
$$R(a,b)=\begin{cases} R(b,a) & \text{if } a<b,\\ R\Big(\left\lfloor\dfrac{a}{b}\right\rfloor,b\Big) & \text{if } 1<b\le a,\\ a & \text{if } 1=b\le a, \end{cases} $$Given two positive integers \(g\) and \(h\), your task is to find two positive integers \(a\) and \(b\) such that
- \(\gcd(a,b)=g\), and
- \(R(a,b)=h\).
Note: It is guaranteed that a solution exists. In fact, one may prove that a necessary condition for the existence of a solution is \(g\) divides \(h\). One valid construction is as follows:
- If \(h=g\), output \(a=g\) and \(b=g\).
- If \(h>g\), let \(k=\frac{h}{g}\) (an integer) and output \(a=h+g\) and \(b=h\). It can be verified that \(\gcd(h+g, h)=g\) and \[ R(h+g,h)=R\Big(\Big\lfloor\frac{h+g}{h}\Big\rfloor, h\Big)=R(1,h)=R(h,1)=h. \]
inputFormat
The input consists of two positive integers \(g\) and \(h\) (separated by spaces or newlines), where \(g\) divides \(h\) and \(1 \le g, h \le 10^9\).
outputFormat
Output two positive integers \(a\) and \(b\) separated by a space, satisfying \(\gcd(a,b)=g\) and \(R(a,b)=h\).
sample
1 1
1 1