Not able to solve

can you please give a hint on how to solve this question?

this is my code. https://ide.codingblocks.com/s/328440

Hi, unfortunately due to some technical error, I can’t access the question. Can you please share the screenshot or something similar.

You are provided a sequence of number. All numbers of that sequence is in increasing order (including 1) and whose only prime factors are 2, 3 or 5 (except 1). You need to find the nth number of that sequence. Input Format First line contains integer t which is number of test case. For each test case, it contains an integer n. Constraints 1<=t<=100 1<=n<=10000 Output Format Print nth number of that sequence. Sample Input 2 7 10 Sample Output 8 12 Explanation Sequence : 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ……

Maintain 3 pointers (to the corresponding values in seq[]), one corresponding to the multiplier of 2, other for 3, and other for 5.

Let,

val2 = x
val3 = y
val5 = z

Now, check the minimum of,

2 * seq[x], 3 * seq[y], 5 * seq[z]

The one which is minimum, append it to the seq, and increment the corresponding pointer.

I don’t get what you’re trying to do.

so x wil point to 2, y to 3 and z to 5, right? And if I got min as 4 then where will x point to next?

Yes, good!!
You have the correct idea.

no I am asking once 4 is appended, x will point to 3 or 4?

x, y, and z are just the multipliers for 2, 3 and 5, i.e., they point to the number that will be multiplied nex by 2, 3 and 5 respectively.

So, earlier only 1 is there in the sequence, so all of them point to 1 (x = y = z = 1).

1
^
x, y, z

But, as x leads to the smallest number (2 * 1), therefore 2 is appended and x is incremented to 2. (x = 2, y = z = 1)

1,           2
^            ^
y, z         x

Now, y gives the smallest number (3 * 1), therefore 3 is appended and y is incremented to 2. (x = y = 2, z = 1)

1,     2,           3
^      ^
z      x, y

Now, again x gives the smallest (2 * 2), therefore 4 is appended and x is incremented to the next number = 3.

1,     2,          3,       4
^      ^           ^
z      y           x

thank you so much .

1 Like