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

26869번 - Greatest Common Divisor 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 1024 MB19151477.778%

문제

Gennady is an aspiring programmer. He is currently learning the Euclidean algorithm for computing the greatest common divisor of two positive integers.

Unfortunately, Gennady sometimes confuses the integer division operator (denoted by div) with the remainder operator (denoted by mod). As an example, 37ドル$ div 10ドル = 3$ and 37ドル$ mod 10ドル = 7$.

Here's Gennady's latest implementation of the Euclidean algorithm:

\begin{itemize}

  • Input: two positive integers $x$ and $y$.
  • While $y > 0$:
    • Set $x = x$ div $y,ドル then swap $x$ and $y$.
  • Output: $x$.

As you can see, if Gennady used the mod operator instead of the div operator, his implementation would be correct: the algorithm above would successfully find the greatest common divisor of $x$ and $y$. However, it turns out that even with this nasty bug the algorithm sometimes works correctly!

You are given an integer $n$. Gennady is interested in finding all input pairs $(x, y)$ such that 1ドル \le x, y \le n,ドル the algorithm finishes, and produces the correct output. Let $(x_1, y_1), (x_2, y_2), \ldots, (x_k, y_k)$ be all such pairs in lexicographic order (for all 1ドル \le i < k,ドル either $x_i < x_{i+1},ドル or $x_i = x_{i+1}$ and $y_i < y_{i+1}$).

You are also given $q$ queries. Query $i$ is a positive integer $p_i,ドル and you should print $x_{p_i}$ and $y_{p_i},ドル or report that $p_i > k$.

입력

The first line contains two integers $n$ and $q$ --- the upper bound on the input values and the number of queries (1ドル \le n, q \le 2 \cdot 10^5$).

Each of the next $q$ lines contains a single integer $p_i$ (1ドル \le p_i \le n^2$).

출력

For each query, print two integers. These integers must either be $x_{p_i}$ and $y_{p_i},ドル denoting the $p_i$-th input pair in lexicographic order such that the algorithm finishes and produces a correct output, or -1 -1 if there are less than $p_i$ such pairs.

제한

예제 입력 1

10 13
1
2
3
4
5
6
7
8
9
10
11
12
13

예제 출력 1

2 2
3 3
4 2
4 4
5 5
6 6
7 7
8 8
9 3
9 9
10 4
10 10
-1 -1

힌트

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > ICPC 2022-2023 North-Western Russia Regional Contest G번

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

출처

대학교 대회

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

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