I have checked my code for several times for different situations… But I think the error is in the modular part! Can anyone please help me with that please!!!
Hi, you need to find ( (n*(n+1)*(2*n+1)*(3*n*n+3*n-1))/30 )% m right ? you can follow as below :
- First multiply ‘m’ by ‘30’ and say it as M.i.e M=m*30
- Now just perform normal modulo using M. i.e using the same trick as (a*b)%c=((a%c)*(b%c))%c,take care of overflows
- Let the result of modulo be x; now just divide x by 30 and that’s your final answer
You can refer POWER() method in my solution for more clarity : [http://www.codechef.com/viewsolution/4803010]
For proof of this technique refer : [http://discuss.codechef.com/questions/50953/floori4-editorial/51016]
You need to multiply m by 30 ie M=30*m
@chalubhalu Oh sorry that’s a typo mistake and thanks for the correction
@achaitanyasai Thankyou very much for replying but I am doing the same thing with modulus… I am getting correct answer for some cases but wrong answer for some cases like for n=12 and m=10… Please can you help me with that! I have checked and re-checked my code!