dEEPAK AND pRIMES PROBLEM

WHAT IS GOING WRONG HERE?
IM NOT GETTING IT.

@sounakume
Hello sounak,
a) please check maximum possible value of n and prime corresponding to that n. you will find that it is really big number and ur sieve is not covering that range .
b) you should print primes->at(n-1) (because 0 based indexing).

But im finding the sieve upto the maximam value of n given i.e. 5000000. How big number should i take.??

@sounakume
ok so max value of n is 5000000 but what about 5000000th prime .
your sieve size should be atleast as big as 5000000th prime number.

@sounakume
5000000th prime is 86,028,121 so declare ur sieve array of size 86,028,122 (make it global and of bool datatype)

It worked but I have 1 Qs

Why declare the array globally, why it doesnot work if declared locally in sieve function and i get segmentation fault. Im not using this it any where else accept sieve func.??

@sounakume
there is some constraint on maximum memory we can allocate (i guess 4mb for function not sure) . global scope has higher capacity than function therefore it worked when declared globally .

Ok i didnot know that, thank you.