NZEC error in java code of PRIME1

Please help with my code.I m trying very hard to get it accepted .It ran very well on my pc as well as on ideone but here it is giving an nzec error .How to find this error??I have posted my code here:link text

Can you tell me, why you have this in your code?

boolean is_prime[]=new boolean[32000];
int primes[]=new int[4000];

Well, you have a problem with your loop scope.

Actually, c is increased at each test case iteration. You should initialise your primes and is_prime arrays only once, before running any test case. You know the max value, so just do

int k=(int) Math.sqrt(MAXVALUE)));

and change the location of your loop…

1 Like

I’m also getting NZEC error both on codechef and SPOJ
any idea anyone ?!

primes[] array is storing prime numbers less than sqrt(larger no) as any composite number between 2 numbers r and s can be expressed a multiple of these prime numbers.
Basically i have tried to use segmented sieve of eratosthenes

Thank you very much this was helpfull i got my code accepted . But can you tell me why it was NZEC error???

Your previous code generated an exception, because c exceeded the size of the array. In code chef, throwing an exception gives NZEC.