#P5968. [POI 2017] Reprezentacje ró?nicowe

[POI 2017] Reprezentacje ró?nicowe

Problem Description

Given a sequence aa:

  • When n2n \le 2, an=na_n = n.
  • When n>2n > 2 and nn is odd, an=2×an1a_n = 2 \times a_{n-1}.
  • When n>2n > 2 and nn is even, an=an1+rn1a_n = a_{n-1} + r_{n-1}.

Here, $r_{n-1} = \operatorname{mex}(|a_i - a_j|)(1 \le i \le j \le n - 1)$, and mex{S}\operatorname{mex}\left\{ S \right\} denotes the smallest non-negative integer that is not in the set SS.

The first several terms of the sequence aa are:

$1,2,4,8,16,21,42,51,102,112,224,235,470,486,972,990,1980$.

It can be proven that for any positive integer xx, there exists a unique pair of integers (p,q)(p, q) such that x=apaqx = a_p - a_q, which is defined as repr(x)\operatorname{repr}(x).

For example, repr(17)=(6,3)\operatorname{repr}(17) = (6, 3), and repr(18)=(16,15)\operatorname{repr}(18) = (16, 15).

Now there are nn queries. Each query gives a positive integer xx. For each query, output repr(x)\operatorname{repr}(x).

Input Format

The first line contains a positive integer nn.

The next nn lines each contain a positive integer xx, representing a query.

Output Format

Output nn lines. Each line contains two positive integers p,qp, q, answering each query in order.

2
17
18
6 3
16 15

Hint

For 100%100\% of the testdata, 1n1051 \le n \le 10^5, and 1x1091 \le x \le 10^9.

Translated by ChatGPT 5