Doubt in the code

I was not able to solve the question ,so I opened the solution ,still not able to get anything out of it ,please explain the method to do it in parts so that I can do it.What are the steps to be followed

Just simulate what you have read about the question. How ? Use Sieve of Eratosthenes and store first 10^6 prime numbers, and create stacks dynamically as when you need them.

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.