Greatest Common Divisor

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

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, 3737 div 10=310 = 3 and 3737 mod 10=710 = 7.

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

\begin{itemize}

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

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 xx and yy. However, it turns out that even with this nasty bug the algorithm sometimes works correctly!

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

You are also given qq queries. Query ii is a positive integer p_ip\_i, and you should print x_p_ix\_{p\_i} and y_p_iy\_{p\_i}, or report that p_i>kp\_i > k.

입력

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

Each of the next qq lines contains a single integer p_ip\_i (1p_in21 \le p\_i \le n^2).

출력

For each query, print two integers. These integers must either be x_p_ix\_{p\_i} and y_p_iy\_{p\_i}, denoting the p_ip\_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_ip\_i such pairs.