Logo
(追記) (追記ここまで)

20202번 - Euklid 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB229715130.178%

문제

It is rarely mentioned that Euclid’s grandma was from Vrsi in Croatia. It is from there that Euclid’s less known (but equally talented in his youth) cousin Edicul comes from.

It happened one day that they were playing “invent an algorithm”. Edicul writes two positive integers on the sand. Then he does the following: while neither number on the sand is 1, he marks them as \((a, b)\) so that \(a \ge b\). Then the numbers are erased and he writes \((\left\lfloor\frac{a}{b}\right\rfloor, b)\) on the sand, and repeats the process. When one of the two numbers becomes 1, the other is the results of his algorithm.

Formally, if \(a\) and \(b\) are positive integers, the result \(R(a, b)\) of Edicul’s algorithm is:

\[R(a,b) = \begin{cases} R(b,a) & \text{if } a < b \text{,} \\ R(\left\lfloor\frac{a}{b}\right\rfloor, b) & \text{if } a \ge b > 1 \text{,} \\ a & \text {if } a \ge b = 1 \text{.} \end{cases}\]

Euclid thinks for a while, and says: “Edicul, I have a better idea...”, and the rest is history. Unfortunately, Edicul never became famous for his idea in number theory. This sad story inspires the following problem:

Given positive integers \(g\) and \(h\), find positive integers \(a\) and \(b\) such that their greatest common divisor is \(g\), and the result of Edicul’s algorithm \(R(a, b)\) is \(h\).

This sets up a pun in Croatian. The translation is a bit bland, sorry for that.

입력

The first line contains a single integer \(t\) (\(1 \le t \le 40\)) – the number of independent test cases.

Each of the following \(t\) lines contains two positive integers \(g_i\) and \(h_i\) (\(h_i \ge 2\)).

출력

Output \(t\) lines in total. For the i-th testcase, output positive integers \(a_i\) and \(b_i\) such that \(gcd(a_i, b_i) = g_i\) and \(R(a_i, b_i) = h_i\).

The numbers in the output must not be larget than 1018. It can be proven that for the given constraints, a solution always exists.

If there are multiple solutions for some testcase, output any of them.

제한

In all subtasks, 1 ≤ g ≤ 200 000 and 2 ≤ h ≤ 200 000.

서브태스크

번호배점제한
14

g = h

28

h = 2

38

g = h2

415

g, h ≤ 20

540

g, h ≤ 2000

635

No additional constraints.

예제 입력 1

1
1 4

예제 출력 1

99 23

예제 입력 2

2
3 2
5 5

예제 출력 2

9 39
5 5

힌트

Clarification of the first example:

The integers \(99\) and \(23\) are coprime, i.e. their greatest common divisor is 1. We have \(\left\lfloor\frac{99}{23}\right\rfloor = 4\), thus \(R(99, 23) = R(4, 23) = R(23, 4)\). Then \(\left\lfloor\frac{23}{4}\right\rfloor = 5\), so \(R(23, 4) = R(5, 4) = R(1, 4) = R(4, 1) = 4\).

Clarification of the second example:

For the first testcase, \(gcd(9, 39) = 3\) and \(R(9, 39) = 2\).

For the second testcase, \(gcd(5, 5) = 5\) and \(R(5, 5) = 5\).

출처

Contest > Croatian Open Competition in Informatics > COCI 2020/2021 > Contest #2 3번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /