Nazif, Osman, and Squares

View as PDF

Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem types

Nazif and Osman are studying for the extremely hard mathematics finals. They practice writing numbers in a difference of two squares format.

Nazif will give Osman \(\mathbf{N}\) lines, one positive integer \(\mathbf{X}\) in each line. Osman must print 2 positive integers \(\mathbf{a, b}\) if \(\mathbf{X}\) can be written in the form \(\mathbf{a^2-b^2}\) and print -1 otherwise. Note that the order of printing \(\mathbf{a}\) and \(\mathbf{b}\) does not matter. Can you help Osman find the numbers?

Input:

The first line will contain \(\mathbf{N}\). Following \(\mathbf{N}\) lines will each contain one single integer \(\mathbf{X}\).

\(1 \leq \mathbf{N} \leq 10^4\)

\(2 \leq \mathbf{X} \leq 10^6\)

Output:

In exactly \(\mathbf{N}\) lines, if \(\mathbf{X_i}\) can be written in the form \(\mathbf{a^2 - b^2}\), you should print two space-separated positive integers \(\mathbf{a}\) and \(\mathbf{b}\). Otherwise, you should print -1. If there is more than one possible answer, you can print any of them.

Examples:

Input 1:

2
6
12

Output 1:

-1
4 2

Input 2:

3
31
47
56

Output 2:

16 15
24 23
15 13