#K39972. Triangular Number Checker

    ID: 26539 Type: Default 1000ms 256MiB

Triangular Number Checker

Triangular Number Checker

In this problem, you are given an integer (X). Your task is to determine whether (X) is a triangular number. A triangular number (T_n) is defined by the formula (T_n = \frac{n(n+1)}{2}) for a positive integer (n). If (X) matches (T_n) for some (n > 0), you should output that value of (n); otherwise, output (-1).

The problem requires you to process multiple test cases. For each test case, read an integer (X) and output the corresponding (n) if (X) is triangular, or (-1) if it is not.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (T) denoting the number of test cases. Each of the next (T) lines contains a single integer (X).

outputFormat

For each test case, output a single line to standard output (stdout) containing the integer (n) if (X = T_n = \frac{n(n+1)}{2}) for some (n>0), or (-1) otherwise.## sample

3
3
10
5
2

4 -1

</p>