
To defeat Ozymandias, Ninja needs all the values which satisfy f(x, y) == z.
Help Ninja to find all the positive integers x and y where f(x, y) == z.
Note: here monotonically increasing function f(x, y) means:
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains a single integer ‘Z’ representing the function value.
Output Format :
For each test case, return a 2-D array denoting the ‘X’ and ‘Y’ values, respectively.
Return the output in sorted order first based on ‘X’, and if ‘X’ is equal, then based on ‘Y’.
The output for each test case is printed in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= Z <= 100
1 <= X,Y <= 2000
Time limit: 1 second
2
5
10
1 4
2 3
3 2
4 1
1 10
2 5
5 2
10 1
Test Case 1: The hidden function for this test case is F(x, y) = x + y
and to make F(x, y) == 5,
We have 1 + 4 == 2 + 3 == 3 + 2 == 4 + 1 == 5
Test Case 2: This test case’s hidden function is F(X, Y) = X * Y.
To make F(X, Y) == 10
1 * 10 == 2 * 5 == 5 * 2 == 10 * 1 == 10
2
9
6
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
1 6
2 3
3 2
6 1
Try to check on all possible ‘X’ and ‘Y’ values as values are not more than 1000.
Here, the idea is to try all possible values of ‘X’ and ‘Y’ and insert the values in the array if F(X, Y) == Z.
Algorithm:
O(X * Y), where ‘X’ and ‘Y’ is the maximum value that we can pass in the function.
For each value of ‘X’, we are checking the function on all values of ‘Y’.
O(1)
Since we are not using any extra space for finding out the answer the space complexity will be O(1).