My code is passing all the test cases except one. I am not able to understand why it is coming run error

Here is my code

The 500,000th prime is 7,368,787

so make size of p array at least 7million

It is showing segmentation fault by increasing the size of array

ideally it should be not give segmentation fault for size
7400000
if it is giving then try to
make the array global

Modified Code