Help in Java.. getting NZEC error, checked all possiblities of this error

Problem Link:- clicke Here
solution link :- click here

when i am solving problem on my pc, i am getting correct answer even on maximum limits of N… in this problem N can be max 1000000
but on submission getting NZEC on spoj


Possiblity of error:-

  1. IndexOutofBound:- according to me, no issues in it
  2. I am creating long type arrays of size 10^6, may be or not this is causing error… if yes, what to do to
    extend memory further

My Approach:- I use sieve method to calculate phi value for all i from 1 to n
I am doing PreCompution of ans in PrefixSumFRange array of size N+1== 1000001

Concepts used:-Euler’s Totient Function
Pillai’s arithmetical function

I think my approach and implementation is correct(so no need to underStand that),as i solved 1 more similar kind of problem and got Ac

Spoj is notorious for java users. If you know your algorithm and logic is correct then try to convert it to C++ code and then submit.

1 Like

but Bro, that is not solution to our problem, it is just a way to skip it… every Problem have some reason which we have to resolve

There is a same problem on UVA. https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2421

Try submitting on UVA

Try to change GCDEX class name to Main.

I’m not completely sure that this hint helps, since I found this information in 15 years old forum post and I used JAVA on SPOJ very long time ago.

That generally shows compile time error. Not NZEC i guess

1 Like

still RunTime Error on Uva, it means something is wrong someWhere in code, which we are not able see

Got AC.
Just changed the way i was taking reading input
instead of reading line by line – s.readLine(); and typeCast String to Integer
i replaced those both lines with N=s.nextInt()


but still not able to figure out whats was wrong with first approach of input taking via readLine()

Saw a comment on spoj page 2
The input may end with EOF instead of 0 in the sample input. Maybe this is why there was a runtime error

@vbt_95 2 “The input may end with EOF instead of 0 in the sample input.”

if this is the case than s.nextInt() should throw exception because it is also looking for 0 to terminate

I thought you used s.hasNextInt() method of scanner.
Then i think the input is not perfect. Trailing whitespaces( like "123 " can throw runtime error when you use Integer.parseInt on string. Try to use trim() after readLine() and then parse into int.