Prateek Loves Candy Challenge

https://ide.codingblocks.com/s/71149
Time limit is exceeding in this problem.

in your approach you are checking for each number whether it is prime or not and if its prime you are increasing counter till you reach n…this approach is fine but if you see the input constraints this approach will not work…in this ques you need to find out prime numbers using some other optimized approach(sieve of eratosthenes)…after that also you will need some optimization as no. of tc are large…

Hey Cheshtha,
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.

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.


i have used sieve of eratosthenes but till how do i know the length of boolean array to be created .