NZEC in Spoj COMDIV. Please help me fix it.

The problem link :
This is what I did:
Constantly getting NZEC. Please let me know what is causing the runtime error.
Besides time limit is strict for slower languages like java to pass as there are only 20 accepted submissions for java for this problem. I don’t know whether my code will result in a TlE or not. Still any advice and tips to speed up or optimize my solution will be extremely helpful.
Thank you.

Update: I generated a large number of test cases for the problem. See here. when I tried to run the program for (t>10^3) it gave ArrayIndexOutOfBounds Exception which i believe was causing NZEC. Then I changed the while loop at line 55 from

while(primes[i]*primes[i]<=g) e to i<p_idx && primes[i]*primes[i]<=g .

Now the NZEC is gone but now I get TLE. So what to do next? :frowning:

1 Like

I code in C++. So, I can’t tell you whats wrong with your code but I can tell you about NZEC error (Common in C++/Java)

Why do I get an NZEC?
NZEC stands for Non Zero Exit Code. Usually this error occurs when the code returns a non-zero value from main() function or if you omit an return 0; from the code. Other languages like Java/C++ could generate this error if they throw an exception which was not caught (e.g. Trying to allocate too much memory in a vector).

So for Java : NZEC will usually mean that your program either crashed or raised an uncaught exception.

Happy Coding :slight_smile:

@amitt001 Yes it was an ArrayIndexOutOfBounds Exception. thanks :slight_smile: I have added an update to the post. please let me know if you have anything else to suggest regarding the TLE.