prime1 getting runtime error on codechef but working on ideone

I am getting runtime error on codechef but my code is working properly on ideone please check my code
my solution on codechef is: CodeChef: Practical coding for everyone
on ideone is:nTBlQD - Online C++ Compiler & Debugging Tool - Ideone.com

It is giving RTE because your code is not able to allocate the required memory, n is large here and its always not possible to allocate. Try thinking of this way: for numbers upto 10^9, the maximum number of prime numbers can be nearly 32000 only(sqrt of n). Then proceed forward using normal sieve and segmented sieve.