Segmentation fault is coming could u tell me whats wrong in this code
you have to do some changes in your code
-
use long long int instead of int
-
data type of p array should be bool not int as you are storing 0 and 1 only
-
The 500000th prime is 7368787
roughly 74*10^5
do all these changes and then try
you have to do this at
for(int j=i*i;j<n;j+=i){
and you have not done it
because here you are squaring i i and go till 10^5 whose square will overflow the int and cause segmentation fault
there are many mistakes in your code
even your sieve function is not correct
i have done all the changes
you can see them in modified code below
Modified Code