#P9703. Find the Smallest n and m from the Expression Value
Find the Smallest n and m from the Expression Value
Find the Smallest n and m from the Expression Value
You are given the value of the following expression: [ \frac{\left(\sum\limits_{i=1}^{n} i\right) - m}{n-1} ] where (m \in [1, n]) and both (n) and (m) are positive integers. In other words, if (S = \frac{n(n+1)}{2}) denotes the sum of the first (n) positive integers, the expression becomes [ \frac{S - m}{n-1} ] You are given an integer (X) which is the value of the expression and you need to find any pair of integers ((n, m)) such that [ \frac{n(n+1)/2 - m}{n-1} = X ] and (1 \le m \le n). If there are multiple valid solutions, output the one with the smallest (n).
The input contains multiple test cases.
inputFormat
The first line contains an integer (T), the number of test cases. Each of the following (T) lines contains one integer (X), representing the known value of the expression.
outputFormat
For each test case, output two integers (n) and (m) (separated by a space) that satisfy the equation (\frac{n(n+1)/2 - m}{n-1} = X) with (1 \le m \le n). If multiple solutions exist, choose the one with the smallest (n).
sample
3
1
4
7
2 2
6 1
12 1
</p>