On Friday, 30 January 2015 13:31:27 UTC+2, samuel jawahar wrote: > Hello,for some problems java will not give correct results > even Algorithm is correct > example > even for small n's it is not working > is it because of java mod function? > example: > my codecheff id:jawa2code > my Algo: > http://discuss.codechef.com/questions/58496/seagcd-editorial > > my code: > http://www.codechef.com/viewsolution/5569341 > regards > Samuel
In line "result = (long) (result - Math.pow(fc, N));" you might get negative value in "result", making module also negative. Also I would be worried to operate with Math.pow() which will give floating point as result. Check BigInteger.modPow(). You can try to add lines right after "result %= mod;" and before the final output put "if (result < 0) result += mod;". P.S. Checked the post date only after writing the answer. :/ -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/8e353074-bf6d-4280-ae2d-f2a2d0c73a89%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
