
A prime number is a number that has only two unique factors, one and the number itself. E.g., 3 has only 2 factors, 1 and 3 itself.
Given ‘N’ = 4, ‘K’ = 2, ‘ARR’[] = 1, 2, 3, 5
The answer is 1 and 3 because :
½ = 0.50
⅓ = 0.33
⅕ = 0.20
⅔ = 0.66
⅖ = 0.40
⅗ = 0.60
Therefore the 2nd smallest value is 0.33 therfore 1 and 3 is the answer.
The first line of input contains an integer ‘T’ denoting the number of test cases. The 'T' test cases follow.
The first line of each test case contains 2 space-separated integers, ‘N’ and ‘K,’ where ‘N’ is the number of elements of the array, and you have to tell the fraction that makes the ‘K’th smallest fraction.
The second line of each test case contains ‘N’ space-separated integers, denoting the array elements.
For each test case, print two integers denoting numerator and denominator respectively of the smallest fraction.
The output of each test case will be printed in a separate line.
You don’t need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 1000
1 <= K <= (N) * (N - 1) / 2
1 <= ARR[ i ] <= 10 ^ 4
Where 'ARR[i]' denotes the 'ith' element of ARR.
Time limit: 1 sec
The main idea is to find all fractions of all pairs of elements in the array and sort them, then return the ‘Kth’ smallest element, which will be at the (K - 1)th index.
The main idea is to use a priority queue ‘QUE’ which stores the value of the fraction and the indices of elements that contribute to that fraction. The priority queue sorts the value based on the fraction values in ascending order. Pop the top K values and add values that are greater than the current value of the fraction. After K, such iteration, the top value will be our answer.