Eratosthenes prime sieve problem

I am getting wrong answers for big numbers inspite of using long long. Please help

hello @rahul.gupta03111999

find value of 50 000th prime number and declare ur max value greater than that.

I am getting 0 as the 50000th prime number. What do I do ?

Also when I am increasing the value of max by power of 10, I am getting a segmentation fault

a)check 50 000th prime number value from internet .
b) now assign any value greater than that to max .
c) make ur array global

make these changes and ur code will work

Thank you sir, the code worked.Sir,can you also please tell me why I need to make max equal to 50000th prime number?

in problem given n<=50 000 ,
so we are required to build sieve of size atleast equal to value of 50 000th prime number to find nth prime (where n can be upto 50 000 )

But SIr, n<=500000 in the question , why do I take 50000

yeah it was a typo , i missed one zero

Also sir why do we take prime array as global

In global scope we can declaree large size arraay compared to function/local scope

1 Like

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.