You are given an integer ‘NUM’. Your task is to find out two numbers ‘FIRST’ and ‘SECOND’ such that their product is equal to either ‘NUM’ + 1 or ‘NUM’ + 2 and their absolute difference is the minimum between all such pairs.
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the ‘T’ test cases follow.
The first line of each test case contains a single positive integer, ‘NUM’.
Output Format:
For each test case, print 2 integers ‘FIRST’ and ‘SECOND’ as described in the problem statement and 'FIRST <= 'SECOND'.
The output of each test case will be 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’ <= 10
1 <= ‘NUM’ <= 10^8
Time Limit: 1 sec
1
10
3 4
‘NUM’ + 1 is equal to 11 for which the answer would be 1 and 11, for ‘NUM’ + 2, which is 12 the answer will be 3 and 4. Hence the better answer is 3 and 4.
1
5
2 3
Find all the factors for ‘NUM’ + 1 and choose the best pair amongst them. Repeat the process for ‘NUM’ + 2.
O(sqrt(N)), where N is the number whose factors we are searching, here it is equal to NUM + 1 and NUM + 2.
Factors of a number can be calculated in sqrt(N) time.
O(1)
We aren’t really storing anything apart from 2 variables FIRST and SECOND.