Playing with cards in stack problem

divisible by ith prime number can you please explain with the
given sample input

@AbhishekAhlawat1102,
You have to run a loop Q times to check for every i prime number.

for(int i=1;i<=q;i++)
{

For each value of i, process A(i-1)th stack.
While processing, check if the elements of A(i-1)th stack are divisible by i prime number or not.
if it is divisible add that number to B(i)th stack(B is set of stacks).
If not then push that element to A(i)th stack.

}

Print all the stacks of B i.e. from B(0) to B(Q) and then A(Q) stack at last.

how does counting for top start for example 5 is on top when by which prime number it should be divisible

then**----------------

Can you please give me a full test case of your query?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.