I am not able to understand question properly ,please help me with some test cases having q>1.
Do not able to understand question properly
hi vikash
In this question we will use three stacks at a time. Stack1 is for storing the given cards.
For a particular ith iteration stack2 stores that cards which are divisible by ith prime number and rest of the cards are stored in stack3.
For the next iteration stack3 is now stack 1 and same steps are repeated.
Here Prime is the array of prime numbers.
For every iteration print the cards in stack2 and after the queries are over print the cards in stack1.