

If N = 12 and K = 5, then we have to find the 5’th factor of 12 out of the list of all factors of 12 : [1, 2, 3, 4, 6, 12], the 5’th factor in the list is 6. Hence, the output is 6.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then ‘T’ test cases follow:
The first and only line in each test case contains two space-separated positive integers ‘N’ and ‘K’, where 'N' is the positive integer whose factor is to be found, ‘K’ is the ‘K’th number in a sequence of all the factors of ‘N’ arranged in ascending order.
For each test case, return the ‘K’th factor of the given positive integer ‘N’. If the ‘K’th factor does not exist, print -1.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 50
1 <= N <= 10^5
1 <= K <= N
Time limit: 1 sec
The idea is to simply check each number from 1 to ‘X’ whether it is a factor of ‘X’ or not, where ‘X’ is the positive integer whose ‘Kth’ factor is to be found.
The steps are as follows:
This approach works because the upper limit till which we need to iterate to find all the factors of ‘N’ is ‘square root of (N)’.
Why is “square root of (N)” is the upper limit?.
We will use this idea to find the ‘Kth’ factor of ‘N’.
The steps are as follows: