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: http://www.codechef.com/viewsolution/4829725
on ideone is:http://ideone.com/nTBlQD

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.

//