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:-
IndexOutofBound:- according to me, no issues in it
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
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
June 26, 2018, 4:29pm
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.
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
June 26, 2018, 5:47pm
June 26, 2018, 7:02pm
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.
June 26, 2018, 7:09pm
That generally shows compile time error. Not NZEC i guess
still RunTime Error on Uva, it means something is wrong someWhere in code, which we are not able see
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()
June 27, 2018, 12:03am
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
June 27, 2018, 11:26am
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.