Under construction

Still being built. Things may change

Greatest Common Divisor

Time limit5sMemory limit1024 MB

Summary
Given n and queries p, find the p-th pair (x, y) in lexicographic order where Gennady's div-based Euclid finishes and outputs the true gcd.
Level

Hard8 of 10

Topics
Number theory, Math, Simulation
Solved
No attempts yet

Problem

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

Gennady often confuses the integer division operator (div) with the remainder operator (mod). For example, 3737 div 10=310 = 3 and 3737 mod 10=710 = 7.

Here is Gennady's implementation of the Euclidean algorithm:

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

If Gennady used mod instead of div, the algorithm would correctly find the greatest common divisor of xx and yy. However, even with this bug, the algorithm sometimes works correctly.

Gennady wants to find all input pairs (x,y)(x, y) such that 1≤x,y≤n1 \le x, y \le n, the algorithm finishes, and produces the correct output. Let (x1,y1),(x2,y2),…,(xk,yk)(x_1, y_1), (x_2, y_2), \ldots, (x_k, y_k) be all such pairs in lexicographic order.

You are also given qq queries. Query ii is a positive integer pip_i. Print xpix_{p_i} and ypiy_{p_i}, or report that pi>kp_i > k.

Input

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

Each of the next qq lines contains a single integer pip_i (1≤pi≤n21 \le p_i \le n^2).

Output

For each query, print two integers: xpix_{p_i} and ypiy_{p_i}, the pip_i-th pair in lexicographic order such that the algorithm finishes and produces a correct output. If there are fewer than pip_i such pairs, print -1 -1.

Examples1

  1. Example 1

    Input
    10 13
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    Expected output
    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