Nth prime number

code is running on giving custom input also getting correct output but on submitting its showing run error


@guptashubham210a
Which question are you solving?
Is it “Prateek loves candy”

yes,I have done using vector but on submitting iits showing error while on giving custom input its correct

Check now.

why you have declare array globally ,I meant to ask why cant we declare inside function primeseive?

because iniatialising array globally sometimes gives allocation error, my doubt is why I cant declare inside primeseive function?

its giving run error on submitting.

I can see that all your test cases were passed.
If you declare array globally, then maximum size of integer array can go upto 10^7.
If you declare it locally or withing main, size greater than order 10^5 will give run error.
Here you have to check prime numbers upto 10^6. So declaring the array as global will handle large test cases

its showing run error now also

see this link I have shown here
https://www.awesomescreenshot.com/video/382804?key=08ff1c3bbf2ce603bbf7a0d91f7dac36

Submit this code and check if still it gives run error.

its working but you told that declaring array >10^5 will give run error

Actually it is 10^6.
Increase it to 10^7 and check, it will give Segmentation fault.

but when we check array by declaring it globally it was not working

It must also work even if you declare the array globally.
https://ide.codingblocks.com/s/283488 Check by submitting.
In your previous code, there must be some other issue. I will check that code and get back to you

Run error is mostly when you are trying to access an array index which was out of bounds(or which was not created). Check in your previous code if this was the case somewhere.

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.