Output correct still wrong answer


I dont know why its happening . Please check and correct me as needed.

In this question, we are given that:
The total cost was a number upto which there are n prime numbers (starting from 2).
So, we need to find the minimum number upto which n prime numbers exist (2 being the first prime number).

For the Sample Input:
2
5
1

The Outputs are:
11
2

In first test case, 11 is the smallest number upto which we have 5 prime numbers(2,3,5,7,11)

In second test case, 2 is the smallest number upto which we have 1 prime number (2)

Since the input constraint is very large and calculating the prime number over again is a costly process in terms of memory, so, we need to use the Sieve of Eratosthenes to solve this question.

You can refer to this video to learn more https://youtu.be/yB57bcffJo4

Hope it helps :slight_smile:

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.


One test case still failing , cannot figure out why.

Hey @abhinavsehgal802_270a44594b6dc4ad,
You were calculating the results till 10^5 thus were missing a test case. The actual value can lie upto 10^6.
Also, instead of iterating over the arr array over and over again. You can simply keep an array where the ith index stores the ith prime number. In that way we can calculate each query in constant time, without looping.

Here’s the updated code.

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.