How do I approach this problem ? Can you pls help me

I do not understand how to procced with the problem ?

Hi!
Try this question by using3 stacks say: st1,st2,st3
st1: for storing cards
in jth iteration:
st2: stores that cards which are divisible by jth prime number
st3: stores rest of the cards

Make an array for prime numbers for the simplicity.

Thanks!