Prateek loves candy

Prateek recently graduated from college. To celebrate, he went to a candy shop and bought all the candies. The total cost was a number upto which there are n prime numbers (starting from 2). Since Prateek wants to minimize his cost, he calls you to help him find the minimum amount that needs to be paid. Being a student of Prateek bhaiya it is now your job to help him out :slight_smile:

please check my code and tell me my mistakes

hello @dhruvk3k

a) u need to find the nth prime .
b) dont use loop to find nth prime , it may give tle because time complexity will be O(T*n).

c ) use seieve and store all prime numbers upto 10^6 in some array or vector and then use that vector to answer each query in O(1)

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.