apoorv_01's blog

By apoorv_01, history, 9 days ago, In English,

Hi! Can someone help me debug my code for this problem 431-C

I think I am making some mistake with the modulo (10^9+7)

Here is my code

Thanks!

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
9 days ago, # |
  Vote: I like it +12 Vote: I do not like it

One of the bugs can be on the last line in main() where you are subtracting two numbers which are % MOD. It can go negative. Do it in this way: (a — b + MOD) % MOD

  • »
    »
    9 days ago, # ^ |
      Vote: I like it +12 Vote: I do not like it

    Thanks! that was the exact problem. Still can you explain why we exactly do that(a-b+MOD)%MOD I now get it that a-b can be negative but still can't understand why we exactly add MOD to a-b (won't adding affect our answer ?)

    • »
      »
      »
      9 days ago, # ^ |
        Vote: I like it +12 Vote: I do not like it

      Adding by mod is equivalent to adding by zero.

      • »
        »
        »
        »
        9 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Oh!!!!! Damn I am stupid Thanks for clearing that out.