

Input: 'K' = 10
Output: 45
The array will contain elements that only have 3, 5 or 7 as their prime factors i.e. of the following form:- 3,5,7,9,15,21,25,…. Therefore we can see from the above pattern of elements that 45 would be the 10th element in the array which is our required answer.
The first line of input contains an integer ‘T’ denoting the number of test cases to run.
Then the test cases follow:-
The first and the only line of each test contains an integer 'K', denoting the Kth number that we want.
For each test case, return the Kth element from the array.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= K <= 3 * 10^3
Time limit: 1 second
The key observation here is to notice a simple fact that the Kth element would always be of the form:-
Kth Multiple of 3, 5 and 7 = 3k * 5k * 7k
We can simply iterate through from 1 to ‘k-1’ and Initialize three queues say Q3, Q5, Q7 and an integer variable say ‘X’ = 1. Keep track of the minimum element among the queues and make that the next value of ‘X’ in our array.
The algorithm for the same can be as follows:-