Playing with cards(in stack)

2 out of 3 test cases giving wrong answer
https://ide.codingblocks.com/s/68649
https://hack.codingblocks.com/contests/c/537/493

Hi Sanyam, it appears that you haven’t understood the structure of question. It is given that there will be Q stacks named as B1, B2 … BQ and Q+1 stacks named A0, B1 … BQ. Hence you cannot use 1 stack instead you have to use an array/vector of stacks.
Also in Line 60 you are calling seiveOfEratosthenes() again and again which is not at all required. Just implement run function once at the start of main and keep an array named prime which will store the ith prime numbers. After that you just need to use line 60 as:

int p = prime[i] ;

Please try the question again now. Hope this helps :slight_smile:

But, I have also used arrays of stacks a and b in lines 42 and 43.

Hi Sanyam, you are also not taking the input correctly. In input you are only given the contents of stack A0 but you are taking them input across all A stacks. After you input q and n you have to just take input int A0 stack i.e.:

for i : 0 -> n :
    int x ;
    cin >> x ;
    a[0].push(x) ;

This is how you have to take input in this question. The rest is fine except that sieveofEratosthenes repeating again and again. Just use/call this function once.

Hope this helps :slight_smile:

Hey Sanyam,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.