I need some clarification of the question what it does means by q that is iteration,
As far as I have considered I have to prepare one stack containg all prime no. and rest rest other stack equals to the size of prime (containing)stack, in which all the numbers are divisible by one no.
Is it so???
please clarify the question and suggest some approach
because creating so many stack containg no. divisible by prime no. what cause tle, even if I am using sieve of erathosenes.
Playing with cards question
hey @Divya_321 here q means you can iterate the given stack A of numbers atmost q times and at for every iteration pop all the elements one by one from given stack A and check if it is divisible by ith prime number(like 2 is 1st prime number,3 is second,5 is 3rd prime and so on) and if it is divisible by that prime number push it in stacj B else you have to push it back in A.
In this question you can use three stacks at a time.
- Stack A is for storing the given cards
.2.For a particular ith iteration stack B stores that cards which are divisible by ith prime number(for this use sieve and store all prime numbers in prime array and acces them one by one for each iteration) and rest of the cards are stored in stack C.
3.For the next iteration stack C is now stack A and same steps are repeated until stack A is not empty or until q…
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.
till what prime no . do I need to check for, also for hint only is it a recursive approach @sdevwrat
using sieve make a prime array which store prime upto qth term.
but size of q too isn’t specified
I have implemented your approach here
codeLink:https://ide.codingblocks.com/s/182202
but I am getting error for memset which I am unable to understand please correct the errors and also tell why they are coming