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
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()
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.