The problem link : http://www.spoj.com/problems/COMDIV/

and

This is what I did: http://ideone.com/wAB2k8

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?