Prateek loves candy , TLE error

Shows TLE , even though i used Sieve and same code worked for Deepak and Primes with No TLE error

hey @S19LPPP0159, range of int is not upto 100000001. Change all int to long long int.

it still shows TLE even after long long int.

@S19LPPP0159, share me updated code

its the same link as above.

hey @S19LPPP0159, you are getting TLE becasue for every testcase you are running for loop with high n value. You should maintain a container that will store the all prime number like array where index 1 has 2, index 2 has 3 and so one.
I have made changes to your code. You can check them here.https://ide.codingblocks.com/s/98673.

You have modified it to a different question, In Prateek loves candy, we were supposed to print nth Prime number,
suppose nth=5
then we are supposed to print 11, which is 5th prime number starting from 2.

Hey @Gaurav13998, modified to same question only.You can search that container and get nth prime number. Try to run the code that I have sent you.

@Gaurav13998 for the input
2
5
1
output should be
11
2

hey @S19LPPP0159, okay make it cout<<arr[nth] instead of arr[nth-1], it work fine then. I forgot to change this.

1 Like

@Gaurav13998 thanks it works now

hey @S19LPPP0159 , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved