help in modular arithmetic for FLOORI4

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 :

  1. First multiply ‘m’ by ‘30’ and say it as M.i.e M=m*30
  2. 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
  3. 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 : [][1]

For proof of this technique refer : [][2]


You need to multiply m by 30 ie M=30*m

@chalubhalu Oh sorry that’s a typo mistake and thanks for the correction :slight_smile:

@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!