

Suppose given ‘X’ is 2, ‘Y’ is 3 and ‘BOUND’ is 10 then
The list of all powerful integers is [2, 3, 4, 5, 7, 9, 10] as:
2 = 2^0 + 3^0
3 = 2^1 + 3^0
4 = 2^0 + 3^1
5 = 2^1 + 3^1
7 = 2^2 + 3^1
9 = 2^3 + 3^0
10 = 2^0 + 3^2
1. You do not need to print anything; it has already been taken care of. Just implement the given function.
2. You may return the answer in any order. In your answer, each value should occur at most once.
The first line of input contains a single integer ‘T’ denoting the number of test cases given. Then next ‘T’ lines follow:
The first line of each test case input contains three space-separated integers, where the first integer represents the ‘X’, the second one is ‘Y’ while the third one is ‘BOUND’.
For every test case, return the vector/list of all the required elements which are less than equal to the given ‘BOUND’ in any order.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 1000
1 <= X, Y <= 100
0 <= BOUND <= 10^6
Time Limit: 1 sec
We can use a simple brute force idea to calculate the bounds for the powers ‘i’ and ‘j’.
We know that at the highest bound we need to have, X^i = 10^6. Therefore, taking log to base 2 of both sides we get,
log(X^i) = log(10^6)
=> i * log X = 6 * log (10) (Since log(10) to the base 2 is approx. ~ 3.321928)
=> i * log X ~ 20
=> i = 20 / (log X)
Now, highest value of i is possible at lowest value of ‘X’, as they are inversely proportional.
=> for ‘X’ = 2
=> maximum ‘i’ = 20
So, if ‘i’ <= 20 is not applied, it will give Time Limit Exceeded.
The algorithm to calculate the required will be:-
We can use the log function to determine the bounds for the powers of ‘X’ and ‘Y’. Using this intuition, let's find out how can we calculate the bounds for the powers ‘i’ and ‘j’.
There is a way to find a much smaller bound for the powers.
This formula implies that
The algorithm to calculate the required will be:-