Prateek loves candey -Will the code work after correction or 0 concept

@Utkarshsingh5298291,

You are supposed to use the prime seive optimisation technique (sieve of eratosthenes). Also make sure that you execute the primeseive function that you will make before the test cases only to prevent TLE.

Precompute the prime numbers using sieve technique.

In the sieve technique where you create a boolean array of b+1 size.

And start from the first prime number i.e. 2. Take its square(4) and increment it by the number you took (i.e. 4,6,8,10 and so on). Mark all these as false since they cannot be primes.

Now take the next unmarked number, 3. And mark 9,12,15 and so as false. Similarly do it for 4. 16,20,24 and so on as false.

When you finish the loop, count all the positions marked as true and when count is equal to the given test case value print that index. This will be our final answer.

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.

https://ide.codingblocks.com/s/237630 can you please check my code and tell the wrong things and correct the code.

@Utkarshsingh5298291,
https://ide.codingblocks.com/s/237676 corrected code.

Precompute all prime numbers first. And store them in a Arraylist. After that simply just get the numbers via the index. The key is to store the prime numbers first.

sir ek baat bataao ki abhi maine topics jo cover kiye hai vo hai basics walle jab list wagerah aaya hi nahi abhi to ispee questions kyu aa rhe

@Utkarshsingh5298291,
I thought you have done arraylist. Don’t worry this can be done without using arraylist as well. Just count the prime number as you were doing it previously

loop kaha tak chlega maine n tak chalaya hai ,but i know kuch aur hoga

@Utkarshsingh5298291,
https://ide.codingblocks.com/s/238160 this is without arraylist.

ans[ ] array is storing the answer that is the count of indexs ? right

@Utkarshsingh5298291,
We are storing the ith prime number in ans[ ] array. When we find a prime number we increment k and store it in the next index.