My code works for the given test cases but I get an NZEC in the codechef compiler. I believe the problem is not that simple as it looks however I do not understand where my code went wrong.
Here is my code: http://www.codechef.com/viewsolution/2529208
Any help regarding how to fix this NZEC problem would be extremely helpful.
Thank You.
You are getting a NumberFormatException
.
The input number can be of ~1000000
digits. Such HUGE numbers are clearly out of the range of numbers representable by a long
in Java.
So, the line long num=Long.parseLong(br.readLine().trim());
throws a NumberFormatException
.
Thank you for your response. I have modified the code by throwing NumberFormatException.
http://www.codechef.com/viewsolution/2529485
but I still get NZEC. And my code gives outputs for even 15digit numbers like here is a sample test case that I had tried.
1
9999999999999999
10000000000000001
I really don’t understand what is the problem. can you please elaborate a little more. Please correct me if I’m wrong somewhere.
Just adding a throws NumberFormatException
clause does not mean that you will not get it again.
Try entering a larger number, like 10000000000000000000000000000000000000000
and see what happens. this is only 41
digits. Now, imagine what happens when there are ~1000000
digits.
You need to handle the big numbers in special ways.