RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00567

Euklid

Unrated 레이팅 미적용
난이도
1s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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
(
 \(a\)
\(b\)

, 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) =





\(R\)(b, a)
if \(a < b\),
\(R\)(
 \(a\)
\(b\)

, b)
if \(a \ge b > 1\),
\(a\)
if \(a \ge b = 1\).
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\).

제약

Subtask 1 (4 points): \(g = h\)

Subtask 2 (8 points): \(h = 2\)

Subtask 3 (8 points): \(g = h\)^{2}

Subtask 4 (15 points): g, \(h \le 20\)

Subtask 5 (40 points): g, \(h \le 2000\)

Subtask 6 (35 points): No additional constraints. ^{∗}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@@RISE_MATH_BLOCK_0@@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@@RISE_MATH_BLOCK_0@@i\).
The numbers in the output must not be larget than \(10^{18}\). 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.

서브태스크
서브태스크점수설명

1

4점

\(g = h\)

2

8점

\(h = 2\)

3

8점

\(g = h\)^{2}

4

15점

g, \(h \le 20\)

5

40점

g, \(h \le 2000\)

6

35점

No additional constraints. ^{∗}This sets up a pun in Croatian. The translation is a bit bland, sorry for that.

예제 1
입력
1
1 4
출력
99 23
예제 2
입력
2
3 2
5 5
출력
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
 99
23

= 4, thus
R(99, 23) = R(4, 23) = R(23, 4). Then
 23
4

= 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.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2020/2021 Contest 2

평가 및 의견

Euklid

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Euklid

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8