Playing With Cards(In Stack)


Why my code it giving TLE after using prime sieve

Use the optimized prime sieve. You can refer that from the number theory section.(While checking you should ignore the even numbers as they can never be prime).
You can refer this implementation https://ide.codingblocks.com/s/319264