please help me with this question test case 0
Test case 0 is failing due to TLE
to find nth prime no you have to make n iteration acc to your code
but you can optimize it by storing all prime nos in a vector
do it like this ( i have done small modification in your code)check below
thank you,
that makes much more sense
it is more practical now
edit-1
But …
now none test case are passing
edit-2
I included some custom test case and found out that
after 446th prime there are
no prime numbers in ‘primes’ vector it shows 0 after that
yes i just see
your outer for loop is wrong
for(int i= 3; i*i<1000000; i+=2){
it should be i < 1000000
also use long long int
Modified Code
It worked
I got the loop part
can you explain
if there is any reason to use long long int
and thanks a lot for helping
because j is i*i
and this may overflow the int
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.