#P13604. [NWRRC 2022] Greatest Common Divisor
[NWRRC 2022] Greatest Common Divisor
题目描述
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 ) with the remainder operator (denoted by ). As an example, and .
Here's Gennady's latest implementation of the Euclidean algorithm:
- Input: two positive integers and .
- While :
- Set , then swap and .
- Output: .
As you can see, if Gennady used the operator instead of the operator, his implementation would be correct: the algorithm above would successfully find the greatest common divisor of and . However, it turns out that even with this nasty bug the algorithm sometimes works correctly!
You are given an integer . Gennady is interested in finding all input pairs such that , the algorithm finishes, and produces the correct output. Let be all such pairs in lexicographic order (for all , either , or and ).
You are also given queries. Query is a positive integer , and you should print and , or report that .
输入格式
The first line contains two integers and --- the upper bound on the input values and the number of queries ().
Each of the next lines contains a single integer ().
输出格式
For each query, print two integers. These integers must either be and , denoting the -th input pair in lexicographic order such that the algorithm finishes and produces a correct output, or \t{-1 -1} if there are less than such pairs.
10 13
1
2
3
4
5
6
7
8
9
10
11
12
13
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